Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'">
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want to try

<EnableMicrosoftExtensionsConfigurationBinderSourceGenerator>true</EnableMicrosoftExtensionsConfigurationBinderSourceGenerator>

if we use Microsoft.Extensions.Configuration.Binder NuGet package 8.*?

and then remove the attributes which are due to the binding.

Shall we do that when we enable .NET 8?
@jennyf19 @westin-m ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that as an increment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I want to try this with .NET 8.


<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
Expand Down Expand Up @@ -105,17 +109,17 @@
<MicrosoftAspNetCoreAuthenticationJwtBearerVersion>5.0.12-*</MicrosoftAspNetCoreAuthenticationJwtBearerVersion>
<MicrosoftAspNetCoreAuthenticationOpenIdConnectVersion>5.0.12-*</MicrosoftAspNetCoreAuthenticationOpenIdConnectVersion>
<MicrosoftExtensionsCachingMemoryVersion>5.0.0</MicrosoftExtensionsCachingMemoryVersion>
<!-- Microsoft.Extensions.Hosting 5.* are obsoleted -->
<!-- Microsoft.Extensions.Hosting 5.* are obsoleted -->
<MicrosoftExtensionsHostingVersion>6.0.0</MicrosoftExtensionsHostingVersion>
<MicrosoftAspNetCoreDataProtectionVersion>5.0.8</MicrosoftAspNetCoreDataProtectionVersion>
<SystemSecurityCryptographyXmlVersion>6.0.1</SystemSecurityCryptographyXmlVersion>

<!-- CVE-2022-34716 due to DataProtection 5.0.8 -->
<MicrosoftExtensionsLoggingVersion>5.0.0</MicrosoftExtensionsLoggingVersion>
<SystemTextEncodingsWebVersion>6.0.0</SystemTextEncodingsWebVersion>

<!-- Microsoft.Extensions.Configuration.Binder 6.* are obsoleted -->
<MicrosoftExtensionsConfigurationBinderVersion>6.0.0</MicrosoftExtensionsConfigurationBinderVersion>
<MicrosoftExtensionsConfigurationBinderVersion>6.0.0</MicrosoftExtensionsConfigurationBinderVersion>
<MicrosoftExtensionsDependencyInjectionVersion>2.1.0</MicrosoftExtensionsDependencyInjectionVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Security.Claims;
using System.Threading;
Expand All @@ -14,6 +15,9 @@ namespace Microsoft.Identity.Web
internal partial class DownstreamApi : IDownstreamApi
{
/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> GetForUserAsync<TOutput>(
string? serviceName,
Action<DownstreamApiOptionsReadOnlyHttpMethod>? downstreamApiOptionsOverride = null,
Expand Down Expand Up @@ -41,6 +45,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> GetForUserAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -76,6 +83,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> GetForAppAsync<TOutput>(
string? serviceName,
Action<DownstreamApiOptionsReadOnlyHttpMethod>? downstreamApiOptionsOverride = null,
Expand All @@ -102,6 +112,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> GetForAppAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -136,6 +149,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task PostForUserAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -169,6 +185,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> PostForUserAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -204,6 +223,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task PostForAppAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -236,6 +258,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> PostForAppAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -270,6 +295,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task PutForUserAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -303,6 +331,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> PutForUserAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -338,6 +369,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task PutForAppAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -370,6 +404,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> PutForAppAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -406,6 +443,9 @@ ex is InvalidOperationException
#if !NETFRAMEWORK && !NETSTANDARD2_0

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task PatchForUserAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -439,6 +479,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> PatchForUserAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -474,6 +517,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task PatchForAppAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -506,6 +552,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> PatchForAppAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -542,6 +591,9 @@ ex is InvalidOperationException
#endif // !NETFRAMEWORK && !NETSTANDARD2_0

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task DeleteForUserAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -575,6 +627,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> DeleteForUserAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -610,6 +665,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task DeleteForAppAsync<TInput>(
string? serviceName,
TInput input,
Expand Down Expand Up @@ -642,6 +700,9 @@ ex is InvalidOperationException
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async Task<TOutput?> DeleteForAppAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Security.Claims;
using System.Threading;
Expand Down Expand Up @@ -55,6 +56,9 @@ namespace Microsoft.Identity.Web
firstMethod = false;
#>
/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
#endif
public async <#= returnType #> <#= httpMethod #>For<#= token #>Async<#= template #>(
string? serviceName,
<# if (hasInput){ #>
Expand Down
19 changes: 19 additions & 0 deletions src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.Http;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -96,6 +97,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.SerializeInput<TInput>(TInput, DownstreamApiOptions)")]
#endif
public async Task<TOutput?> CallApiForUserAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand All @@ -120,6 +124,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.SerializeInput<TInput>(TInput, DownstreamApiOptions)")]
#endif
public async Task<TOutput?> CallApiForAppAsync<TInput, TOutput>(
string? serviceName,
TInput input,
Expand All @@ -142,6 +149,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(HttpResponseMessage, DownstreamApiOptions)")]
#endif
public async Task<TOutput?> CallApiForAppAsync<TOutput>(string serviceName,
Action<DownstreamApiOptions>? downstreamApiOptionsOverride = null,
CancellationToken cancellationToken = default) where TOutput : class
Expand All @@ -154,6 +164,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(HttpResponseMessage, DownstreamApiOptions)")]
#endif
public async Task<TOutput?> CallApiForUserAsync<TOutput>(
string? serviceName,
Action<DownstreamApiOptions>? downstreamApiOptionsOverride = null,
Expand Down Expand Up @@ -217,6 +230,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
return clonedOptions;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
#endif
private static HttpContent? SerializeInput<TInput>(TInput input, DownstreamApiOptions effectiveOptions)
{
HttpContent? effectiveInput;
Expand All @@ -238,6 +254,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
return effectiveInput;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)")]
#endif
private static async Task<TOutput?> DeserializeOutput<TOutput>(HttpResponseMessage response, DownstreamApiOptions effectiveOptions)
where TOutput : class
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Abstractions;
Expand All @@ -21,6 +22,9 @@ public static class DownstreamApiExtensions
/// This is the name used when calling the service from controller/pages.</param>
/// <param name="configuration">Configuration.</param>
/// <returns>The builder for chaining.</returns>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IServiceCollection, String, IConfiguration).")]
#endif
public static IServiceCollection AddDownstreamApi(
this IServiceCollection services,
string serviceName,
Expand Down Expand Up @@ -65,6 +69,9 @@ public static IServiceCollection AddDownstreamApi(
/// This is the name used when calling the service from controller/pages.</param>
/// <param name="configuration">Configuration.</param>
/// <returns>The builder for chaining.</returns>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Microsoft.Identity.Web.DownstreamApiExtensions.AddDownstreamApi(IServiceCollection, String, IConfiguration).")]
#endif
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddDownstreamApi(
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
string serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -24,6 +25,9 @@ public static class MicrosoftGraphExtensions
/// <param name="builder">Builder.</param>
/// <param name="configurationSection">Configuration section.</param>
/// <returns>The builder to chain.</returns>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Microsoft.Extensions.Configuration.ConfigurationBinder.Bind(IConfiguration, Object).")]
#endif
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftGraph(
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
IConfigurationSection configurationSection)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;

namespace Microsoft.Identity.Web
Expand All @@ -9,6 +10,9 @@ namespace Microsoft.Identity.Web
/// Extension class on IApplicationBuilder to initialize the service provider of
/// the TokenAcquirerFactory in ASP.NET Core.
/// </summary>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Microsoft.Identity.Web.TokenAcquirerFactory.GetDefaultInstance(String).")]
#endif
public static class ApplicationBuilderExtensions
{
/// <summary>
Expand Down
Loading