Skip to content

Commit b2c22cf

Browse files
authored
Annotate Blazor wasm auth assemblies for trimmability (#31119)
Minor cleanup when inspecting the code
1 parent 1c659cc commit b2c22cf

15 files changed

+53
-38
lines changed

src/Components/WebAssembly/Authentication.Msal/src/Microsoft.Authentication.WebAssembly.Msal.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<Sdk Name="Yarn.MSBuild" />
44

55
<PropertyGroup>
66
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
77
<Description>Authenticate your Blazor webassembly applications with Azure Active Directory and Azure Active Directory B2C</Description>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9+
<Trimmable>true</Trimmable>
910
</PropertyGroup>
1011

1112
<ItemGroup>
@@ -16,6 +17,10 @@
1617
<InternalsVisibleTo Include="Microsoft.Authentication.WebAssembly.Msal.Tests" />
1718
</ItemGroup>
1819

20+
<ItemGroup>
21+
<Compile Include="$(SharedSourceRoot)LinkerFlags.cs" LinkBase="Shared" />
22+
</ItemGroup>
23+
1924
<PropertyGroup>
2025
<YarnWorkingDir>$(MSBuildThisFileDirectory)Interop\</YarnWorkingDir>
2126
<ResolveCurrentProjectStaticWebAssetsInputsDependsOn>

src/Components/WebAssembly/Authentication.Msal/src/MsalDefaultOptionsConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Configure(RemoteAuthenticationOptions<MsalProviderOptions> options)
4444

4545
public void PostConfigure(string name, RemoteAuthenticationOptions<MsalProviderOptions> options)
4646
{
47-
if (string.Equals(name, Options.DefaultName))
47+
if (string.Equals(name, Options.DefaultName, StringComparison.Ordinal))
4848
{
4949
Configure(options);
5050
}

src/Components/WebAssembly/Authentication.Msal/src/MsalWebAssemblyServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
67
using Microsoft.Authentication.WebAssembly.Msal;
78
using Microsoft.Authentication.WebAssembly.Msal.Models;
89
using Microsoft.Extensions.DependencyInjection.Extensions;
910
using Microsoft.Extensions.Options;
11+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1012

1113
namespace Microsoft.Extensions.DependencyInjection
1214
{
@@ -48,7 +50,7 @@ public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, RemoteUse
4850
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
4951
/// <param name="configure">A callback to configure the <see cref="RemoteAuthenticationOptions{MsalProviderOptions}"/>.</param>
5052
/// <returns>The <see cref="IServiceCollection"/>.</returns>
51-
public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount> AddMsalAuthentication<TRemoteAuthenticationState, TAccount>(this IServiceCollection services, Action<RemoteAuthenticationOptions<MsalProviderOptions>> configure)
53+
public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount> AddMsalAuthentication<TRemoteAuthenticationState, [DynamicallyAccessedMembers(JsonSerialized)] TAccount>(this IServiceCollection services, Action<RemoteAuthenticationOptions<MsalProviderOptions>> configure)
5254
where TRemoteAuthenticationState : RemoteAuthenticationState, new()
5355
where TAccount : RemoteUserAccount
5456
{

src/Components/WebAssembly/WebAssembly.Authentication/src/IRemoteAuthenticationPathsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal
4+
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
55
{
66
/// <summary>
77
/// This is an internal API that supports the Microsoft.AspNetCore.Components.WebAssembly.Authentication

src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<InternalsVisibleTo Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication.Tests" />
1919
</ItemGroup>
2020

21+
<ItemGroup>
22+
<Compile Include="$(SharedSourceRoot)LinkerFlags.cs" LinkBase="Shared" />
23+
</ItemGroup>
24+
2125
<PropertyGroup>
2226
<YarnWorkingDir>$(MSBuildThisFileDirectory)Interop\</YarnWorkingDir>
2327
<ResolveCurrentProjectStaticWebAssetsInputsDependsOn>

src/Components/WebAssembly/WebAssembly.Authentication/src/QueryStringHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Text.Encodings.Web;
56

67
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
78
{
8-
internal class QueryStringHelper
9+
internal static class QueryStringHelper
910
{
1011
public static string GetParameter(string queryString, string key)
1112
{

src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static class RemoteAuthenticationBuilderExtensions
4949
/// <typeparam name="TAccountClaimsPrincipalFactory">The new user factory type.</typeparam>
5050
/// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{RemoteAuthenticationState, Account}"/>.</param>
5151
/// <returns>The <see cref="IRemoteAuthenticationBuilder{RemoteAuthenticationState, Account}"/>.</returns>
52-
public static IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> AddAccountClaimsPrincipalFactory<TAccountClaimsPrincipalFactory>(
52+
public static IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> AddAccountClaimsPrincipalFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TAccountClaimsPrincipalFactory>(
5353
this IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> builder)
5454
where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory<RemoteUserAccount> => builder.AddAccountClaimsPrincipalFactory<RemoteAuthenticationState, RemoteUserAccount, TAccountClaimsPrincipalFactory>();
5555
}

src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Components.Authorization;
77
using Microsoft.AspNetCore.Components.Rendering;
8-
using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal;
98
using Microsoft.JSInterop;
109

1110
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
@@ -103,9 +102,7 @@ public class RemoteAuthenticatorViewCore<TAuthenticationState> : ComponentBase w
103102
/// <summary>
104103
/// Gets or sets a default <see cref="IRemoteAuthenticationPathsProvider"/> to use as fallback if an <see cref="ApplicationPaths"/> has not been explicitly specified.
105104
/// </summary>
106-
#pragma warning disable PUB0001 // Pubternal type in public API
107105
[Inject] internal IRemoteAuthenticationPathsProvider RemoteApplicationPathsProvider { get; set; }
108-
#pragma warning restore PUB0001 // Pubternal type in public API
109106

110107
/// <summary>
111108
/// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user.

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenResult.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
5-
64
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
75
{
86
/// <summary>

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccountClaimsPrincipalFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class AccountClaimsPrincipalFactory<TAccount> where TAccount : RemoteUser
1616
{
1717
private readonly IAccessTokenProviderAccessor _accessor;
1818

19-
#pragma warning disable PUB0001 // Pubternal type in public API
2019
/// <summary>
2120
/// Initialize a new instance of <see cref="AccountClaimsPrincipalFactory{TAccount}"/>.
2221
/// </summary>

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/DefaultRemoteApplicationPathsProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal;
54
using Microsoft.Extensions.Options;
65

76
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Security.Claims;
6-
using System.Text.Json;
77
using System.Threading.Tasks;
88
using Microsoft.AspNetCore.Components.Authorization;
99
using Microsoft.Extensions.Options;
1010
using Microsoft.JSInterop;
11+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1112

1213
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
1314
{
@@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
1718
/// <typeparam name="TRemoteAuthenticationState">The state to preserve across authentication operations.</typeparam>
1819
/// <typeparam name="TAccount">The type of the <see cref="RemoteUserAccount" />.</typeparam>
1920
/// <typeparam name="TProviderOptions">The options to be passed down to the underlying JavaScript library handling the authentication operations.</typeparam>
20-
public class RemoteAuthenticationService<TRemoteAuthenticationState, TAccount, TProviderOptions> :
21+
public class RemoteAuthenticationService<TRemoteAuthenticationState, [DynamicallyAccessedMembers(JsonSerialized)] TAccount, TProviderOptions> :
2122
AuthenticationStateProvider,
2223
IRemoteAuthenticationService<TRemoteAuthenticationState>,
2324
IAccessTokenProvider

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/SignOutSessionStateManager.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
1313
public class SignOutSessionStateManager
1414
{
1515
private readonly IJSRuntime _jsRuntime;
16-
private static readonly JsonSerializerOptions _serializationOptions = new JsonSerializerOptions
17-
{
18-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
19-
PropertyNameCaseInsensitive = true,
20-
};
16+
private static readonly JsonSerializerOptions _serializationOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
2117

2218
/// <summary>
2319
/// Initialize a new instance of <see cref="SignOutSessionStateManager"/>.

0 commit comments

Comments
 (0)