From 43bd9dbf3edf17d9d7621e466f15e439846c2c67 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 9 Apr 2020 01:08:43 +0200 Subject: [PATCH] [Blazor][Wasm] API review feedback (#20652) * UserFactory->AccountClaimsPrincipalFactory * Change constants to static readonly * Make applicationpaths provider and RemoteAuthenticatorViewCore dependencies internal * Change collection types, make properties get only where possible * Change state constraint to extend RemoteAuthenticationState --- .../src/IRemoteAuthenticationPathsProvider.cs | 2 +- .../src/Models/AccessToken.cs | 3 +- .../src/Models/RemoteAuthenticationResult.cs | 6 +- .../src/Options/OidcProviderOptions.cs | 2 +- .../Options/RemoteAuthenticationOptions.cs | 6 +- .../RemoteAuthenticationBuilderExtensions.cs | 26 +++--- .../src/RemoteAuthenticationDefaults.cs | 18 ++-- .../src/RemoteAuthenticatorViewCore.cs | 12 +-- .../src/Services/AccessTokenRequestOptions.cs | 2 +- .../src/Services/AccessTokenResult.cs | 4 +- ...ry.cs => AccountClaimsPrincipalFactory.cs} | 4 +- .../Services/RemoteAuthenticationService.cs | 12 +-- ...thenticationServiceCollectionExtensions.cs | 2 +- .../test/RemoteAuthenticationServiceTests.cs | 89 +++++++++--------- .../test/RemoteAuthenticatorCoreTests.cs | 2 +- ...icationServiceCollectionExtensionsTests.cs | 90 ++++++++----------- .../PreferencesUserFactory.cs | 2 +- .../Wasm.Authentication.Client/Program.cs | 2 +- 18 files changed, 129 insertions(+), 155 deletions(-) rename src/Components/WebAssembly/WebAssembly.Authentication/src/Services/{UserFactory.cs => AccountClaimsPrincipalFactory.cs} (92%) diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/IRemoteAuthenticationPathsProvider.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/IRemoteAuthenticationPathsProvider.cs index ee7e79081c..2294d7af22 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/IRemoteAuthenticationPathsProvider.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/IRemoteAuthenticationPathsProvider.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal /// infrastructure and not subject to the same compatibility standards as public APIs. /// It may be changed or removed without notice in any release. /// - public interface IRemoteAuthenticationPathsProvider + internal interface IRemoteAuthenticationPathsProvider { /// /// This is an internal API that supports the Microsoft.AspNetCore.Components.WebAssembly.Authentication diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/AccessToken.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/AccessToken.cs index 0b6f831fda..a282d1c794 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/AccessToken.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/AccessToken.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication { @@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the list of granted scopes for the token. /// - public string[] GrantedScopes { get; set; } + public IReadOnlyList GrantedScopes { get; set; } /// /// Gets the expiration time of the token. diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationResult.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationResult.cs index 4af828b37f..529f34e54b 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationResult.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationResult.cs @@ -6,8 +6,8 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Represents the result of an authentication operation. /// - /// The type of the preserved state during the authentication operation. - public class RemoteAuthenticationResult where TState : class + /// The type of the preserved state during the authentication operation. + public class RemoteAuthenticationResult where TRemoteAuthenticationState : RemoteAuthenticationState { /// /// Gets or sets the status of the authentication operation. The status can be one of . @@ -22,6 +22,6 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the preserved state of a successful authentication operation. /// - public TState State { get; set; } + public TRemoteAuthenticationState State { get; set; } } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/OidcProviderOptions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/OidcProviderOptions.cs index 56859689ed..dbb43e1dbf 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/OidcProviderOptions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/OidcProviderOptions.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the list of scopes to request when signing in. /// - public IList DefaultScopes { get; set; } = new List { "openid", "profile" }; + public IList DefaultScopes { get; } = new List { "openid", "profile" }; /// /// Gets or sets the redirect uri for the application. The application will be redirected here after the user has completed the sign in diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/RemoteAuthenticationOptions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/RemoteAuthenticationOptions.cs index 7efb26f44c..b20c2f8b26 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/RemoteAuthenticationOptions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Options/RemoteAuthenticationOptions.cs @@ -12,16 +12,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the provider options. /// - public TRemoteAuthenticationProviderOptions ProviderOptions { get; set; } = new TRemoteAuthenticationProviderOptions(); + public TRemoteAuthenticationProviderOptions ProviderOptions { get; } = new TRemoteAuthenticationProviderOptions(); /// /// Gets or sets the . /// - public RemoteAuthenticationApplicationPathsOptions AuthenticationPaths { get; set; } = new RemoteAuthenticationApplicationPathsOptions(); + public RemoteAuthenticationApplicationPathsOptions AuthenticationPaths { get; } = new RemoteAuthenticationApplicationPathsOptions(); /// /// Gets or sets the . /// - public RemoteAuthenticationUserOptions UserOptions { get; set; } = new RemoteAuthenticationUserOptions(); + public RemoteAuthenticationUserOptions UserOptions { get; } = new RemoteAuthenticationUserOptions(); } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationBuilderExtensions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationBuilderExtensions.cs index 9040a726a7..471b8cef7a 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationBuilderExtensions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationBuilderExtensions.cs @@ -12,44 +12,44 @@ namespace Microsoft.Extensions.DependencyInjection public static class RemoteAuthenticationBuilderExtensions { /// - /// Replaces the existing with the user factory defined by . + /// Replaces the existing with the user factory defined by . /// /// The remote authentication state. /// The account type. - /// The new user factory type. + /// The new user factory type. /// The . /// The . - public static IRemoteAuthenticationBuilder AddUserFactory( + public static IRemoteAuthenticationBuilder AddAccountClaimsPrincipalFactory( this IRemoteAuthenticationBuilder builder) where TRemoteAuthenticationState : RemoteAuthenticationState, new() where TAccount : RemoteUserAccount - where TUserFactory : UserFactory + where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory { - builder.Services.Replace(ServiceDescriptor.Scoped, TUserFactory>()); + builder.Services.Replace(ServiceDescriptor.Scoped, TAccountClaimsPrincipalFactory>()); return builder; } /// - /// Replaces the existing with the user factory defined by . + /// Replaces the existing with the user factory defined by . /// /// The remote authentication state. - /// The new user factory type. + /// The new user factory type. /// The . /// The . - public static IRemoteAuthenticationBuilder AddUserFactory( + public static IRemoteAuthenticationBuilder AddAccountClaimsPrincipalFactory( this IRemoteAuthenticationBuilder builder) where TRemoteAuthenticationState : RemoteAuthenticationState, new() - where TUserFactory : UserFactory => builder.AddUserFactory(); + where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory => builder.AddAccountClaimsPrincipalFactory(); /// - /// Replaces the existing with the user factory defined by . + /// Replaces the existing with the user factory defined by . /// - /// The new user factory type. + /// The new user factory type. /// The . /// The . - public static IRemoteAuthenticationBuilder AddUserFactory( + public static IRemoteAuthenticationBuilder AddAccountClaimsPrincipalFactory( this IRemoteAuthenticationBuilder builder) - where TUserFactory : UserFactory => builder.AddUserFactory(); + where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory => builder.AddAccountClaimsPrincipalFactory(); } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs index 54016a4d1c..51d66c7a9e 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs @@ -11,46 +11,46 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// The default login path. /// - public const string LoginPath = "authentication/login"; + public static readonly string LoginPath = "authentication/login"; /// /// The default login callback path. /// - public const string LoginCallbackPath = "authentication/login-callback"; + public static readonly string LoginCallbackPath = "authentication/login-callback"; /// /// The default login failed path. /// - public const string LoginFailedPath = "authentication/login-failed"; + public static readonly string LoginFailedPath = "authentication/login-failed"; /// /// The default logout path. /// - public const string LogoutPath = "authentication/logout"; + public static readonly string LogoutPath = "authentication/logout"; /// /// The default logout callback path. /// - public const string LogoutCallbackPath = "authentication/logout-callback"; + public static readonly string LogoutCallbackPath = "authentication/logout-callback"; /// /// The default logout failed path. /// - public const string LogoutFailedPath = "authentication/logout-failed"; + public static readonly string LogoutFailedPath = "authentication/logout-failed"; /// /// The default logout succeeded path. /// - public const string LogoutSucceededPath = "authentication/logged-out"; + public static readonly string LogoutSucceededPath = "authentication/logged-out"; /// /// The default profile path. /// - public const string ProfilePath = "authentication/profile"; + public static readonly string ProfilePath = "authentication/profile"; /// /// The default register path. /// - public const string RegisterPath = "authentication/register"; + public static readonly string RegisterPath = "authentication/register"; } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs index 35aaba6e02..b7dbe951e8 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs @@ -88,34 +88,34 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the to use for performin JavaScript interop. /// - [Inject] public IJSRuntime JS { get; set; } + [Inject] internal IJSRuntime JS { get; set; } /// /// Gets or sets the to use for redirecting the browser. /// - [Inject] public NavigationManager Navigation { get; set; } + [Inject] internal NavigationManager Navigation { get; set; } /// /// Gets or sets the to use for handling the underlying authentication protocol. /// - [Inject] public IRemoteAuthenticationService AuthenticationService { get; set; } + [Inject] internal IRemoteAuthenticationService AuthenticationService { get; set; } /// /// Gets or sets a default to use as fallback if an has not been explicitly specified. /// #pragma warning disable PUB0001 // Pubternal type in public API - [Inject] public IRemoteAuthenticationPathsProvider RemoteApplicationPathsProvider { get; set; } + [Inject] internal IRemoteAuthenticationPathsProvider RemoteApplicationPathsProvider { get; set; } #pragma warning restore PUB0001 // Pubternal type in public API /// /// Gets or sets a default with the current user. /// - [Inject] public AuthenticationStateProvider AuthenticationProvider { get; set; } + [Inject] internal AuthenticationStateProvider AuthenticationProvider { get; set; } /// /// Gets or sets a default with the current user. /// - [Inject] public SignOutSessionStateManager SignOutManager { get; set; } + [Inject] internal SignOutSessionStateManager SignOutManager { get; set; } /// /// Gets or sets the with the paths to different authentication pages. diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenRequestOptions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenRequestOptions.cs index 235f6c3855..cffb2fd3dc 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenRequestOptions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenRequestOptions.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the list of scopes to request for the token. /// - public string[] Scopes { get; set; } + public IEnumerable Scopes { get; set; } /// /// Gets or sets a specific return url to use for returning the user back to the application if it needs to be diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenResult.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenResult.cs index 387adb3aaa..14a3e24212 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenResult.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccessTokenResult.cs @@ -28,12 +28,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// /// Gets or sets the status of the current operation. See for a list of statuses. /// - public AccessTokenResultStatus Status { get; set; } + public AccessTokenResultStatus Status { get; } /// /// Gets or sets the URL to redirect to if is . /// - public string RedirectUrl { get; set; } + public string RedirectUrl { get; } /// /// Determines whether the token request was successful and makes the available for use when it is. diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/UserFactory.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccountClaimsPrincipalFactory.cs similarity index 92% rename from src/Components/WebAssembly/WebAssembly.Authentication/src/Services/UserFactory.cs rename to src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccountClaimsPrincipalFactory.cs index 1c7aa980fa..d81a802fa0 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/UserFactory.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/AccountClaimsPrincipalFactory.cs @@ -12,12 +12,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// Converts into a . /// /// The account type. - public class UserFactory where TAccount : RemoteUserAccount + public class AccountClaimsPrincipalFactory where TAccount : RemoteUserAccount { private readonly IAccessTokenProviderAccessor _accessor; #pragma warning disable PUB0001 // Pubternal type in public API - public UserFactory(IAccessTokenProviderAccessor accessor) => _accessor = accessor; + public AccountClaimsPrincipalFactory(IAccessTokenProviderAccessor accessor) => _accessor = accessor; /// /// Gets or sets the . diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs index 030160bfee..30e07e27ba 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs @@ -43,9 +43,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication protected NavigationManager Navigation { get; } /// - /// Gets the to map accounts to . + /// Gets the to map accounts to . /// - protected UserFactory UserFactory { get; } + protected AccountClaimsPrincipalFactory AccountClaimsPrincipalFactory { get; } /// /// Gets the options for the underlying JavaScript library handling the authentication operations. @@ -58,16 +58,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication /// The to use for performing JavaScript interop operations. /// The options to be passed down to the underlying JavaScript library handling the authentication operations. /// The used to generate URLs. - /// The used to generate the for the user. + /// The used to generate the for the user. public RemoteAuthenticationService( IJSRuntime jsRuntime, IOptions> options, NavigationManager navigation, - UserFactory userFactory) + AccountClaimsPrincipalFactory accountClaimsPrincipalFactory) { JsRuntime = jsRuntime; Navigation = navigation; - UserFactory = userFactory; + AccountClaimsPrincipalFactory = accountClaimsPrincipalFactory; Options = options.Value; } @@ -217,7 +217,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication { await EnsureAuthService(); var account = await JsRuntime.InvokeAsync("AuthenticationService.getUser"); - var user = await UserFactory.CreateUserAsync(account, Options.UserOptions); + var user = await AccountClaimsPrincipalFactory.CreateUserAsync(account, Options.UserOptions); return user; } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/WebAssemblyAuthenticationServiceCollectionExtensions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/WebAssemblyAuthenticationServiceCollectionExtensions.cs index 0134071a65..b7c1af973c 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/WebAssemblyAuthenticationServiceCollectionExtensions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/WebAssemblyAuthenticationServiceCollectionExtensions.cs @@ -47,7 +47,7 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddScoped(); services.TryAddScoped(); - services.TryAddScoped>(); + services.TryAddScoped>(); return new RemoteAuthenticationBuilder(services); } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticationServiceTests.cs b/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticationServiceTests.cs index 2493b43dd0..eca45e8913 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticationServiceTests.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticationServiceTests.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult @@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult @@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult @@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult @@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult @@ -260,7 +260,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult @@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult @@ -338,7 +338,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); var state = new RemoteAuthenticationState(); testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult @@ -379,7 +379,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new UserFactory(Mock.Of())); + new AccountClaimsPrincipalFactory(Mock.Of())); testJsRuntime.GetUserResult = default; @@ -406,7 +406,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new TestUserFactory(Mock.Of())); + new TestAccountClaimsPrincipalFactory(Mock.Of())); var account = new CoolRoleAccount { @@ -442,7 +442,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication testJsRuntime, options, new TestNavigationManager(), - new TestUserFactory(Mock.Of())); + new TestAccountClaimsPrincipalFactory(Mock.Of())); var account = new CoolRoleAccount { @@ -481,39 +481,30 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication private static IOptions> CreateOptions(string scopeClaim = null) { - return Options.Create( - new RemoteAuthenticationOptions() - { - AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions - { - LogInPath = "login", - LogInCallbackPath = "a", - LogInFailedPath = "a", - RegisterPath = "a", - ProfilePath = "a", - RemoteRegisterPath = "a", - RemoteProfilePath = "a", - LogOutPath = "a", - LogOutCallbackPath = "a", - LogOutFailedPath = "a", - LogOutSucceededPath = "a", - }, - UserOptions = new RemoteAuthenticationUserOptions - { - AuthenticationType = "a", - ScopeClaim = scopeClaim, - RoleClaim = "coolRole", - NameClaim = "coolName", - }, - ProviderOptions = new OidcProviderOptions - { - Authority = "a", - ClientId = "a", - DefaultScopes = new[] { "openid" }, - RedirectUri = "https://www.example.com/base/custom-login", - PostLogoutRedirectUri = "https://www.example.com/base/custom-logout", - } - }); + var options = new RemoteAuthenticationOptions(); + + options.AuthenticationPaths.LogInPath = "login"; + options.AuthenticationPaths.LogInCallbackPath = "a"; + options.AuthenticationPaths.LogInFailedPath = "a"; + options.AuthenticationPaths.RegisterPath = "a"; + options.AuthenticationPaths.ProfilePath = "a"; + options.AuthenticationPaths.RemoteRegisterPath = "a"; + options.AuthenticationPaths.RemoteProfilePath = "a"; + options.AuthenticationPaths.LogOutPath = "a"; + options.AuthenticationPaths.LogOutCallbackPath = "a"; + options.AuthenticationPaths.LogOutFailedPath = "a"; + options.AuthenticationPaths.LogOutSucceededPath = "a"; + options.UserOptions.AuthenticationType = "a"; + options.UserOptions.ScopeClaim = scopeClaim; + options.UserOptions.RoleClaim = "coolRole"; + options.UserOptions.NameClaim = "coolName"; + options.ProviderOptions.Authority = "a"; + options.ProviderOptions.ClientId = "a"; + options.ProviderOptions.DefaultScopes.Add("openid"); + options.ProviderOptions.RedirectUri = "https://www.example.com/base/custom-login"; + options.ProviderOptions.PostLogoutRedirectUri = "https://www.example.com/base/custom-logout"; + + return Options.Create(options); } private class TestJsRuntime : IJSRuntime @@ -571,9 +562,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication } } - internal class TestUserFactory : UserFactory + internal class TestAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory { - public TestUserFactory(IAccessTokenProviderAccessor accessor) : base(accessor) + public TestAccountClaimsPrincipalFactory(IAccessTokenProviderAccessor accessor) : base(accessor) { } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticatorCoreTests.cs b/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticatorCoreTests.cs index cb3f6b025e..270b59c7c7 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticatorCoreTests.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/test/RemoteAuthenticatorCoreTests.cs @@ -667,7 +667,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication IJSRuntime jsRuntime, IOptions> options, TestNavigationManager navigationManager) : - base(jsRuntime, options, navigationManager, new UserFactory(Mock.Of())) + base(jsRuntime, options, navigationManager, new AccountClaimsPrincipalFactory(Mock.Of())) { } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/test/WebAssemblyAuthenticationServiceCollectionExtensionsTests.cs b/src/Components/WebAssembly/WebAssembly.Authentication/test/WebAssemblyAuthenticationServiceCollectionExtensionsTests.cs index 88fea7c71c..d9996a124d 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/test/WebAssemblyAuthenticationServiceCollectionExtensionsTests.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/test/WebAssemblyAuthenticationServiceCollectionExtensionsTests.cs @@ -200,31 +200,22 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication var builder = new WebAssemblyHostBuilder(new TestWebAssemblyJSRuntimeInvoker()); builder.Services.AddApiAuthorization(options => { - options.AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions - { - LogInPath = "a", - LogInCallbackPath = "b", - LogInFailedPath = "c", - RegisterPath = "d", - ProfilePath = "e", - RemoteRegisterPath = "f", - RemoteProfilePath = "g", - LogOutPath = "h", - LogOutCallbackPath = "i", - LogOutFailedPath = "j", - LogOutSucceededPath = "k", - }; - options.UserOptions = new RemoteAuthenticationUserOptions - { - AuthenticationType = "l", - ScopeClaim = "m", - RoleClaim = "n", - NameClaim = "o", - }; - options.ProviderOptions = new ApiAuthorizationProviderOptions - { - ConfigurationEndpoint = "p" - }; + options.AuthenticationPaths.LogInPath = "a"; + options.AuthenticationPaths.LogInCallbackPath = "b"; + options.AuthenticationPaths.LogInFailedPath = "c"; + options.AuthenticationPaths.RegisterPath = "d"; + options.AuthenticationPaths.ProfilePath = "e"; + options.AuthenticationPaths.RemoteRegisterPath = "f"; + options.AuthenticationPaths.RemoteProfilePath = "g"; + options.AuthenticationPaths.LogOutPath = "h"; + options.AuthenticationPaths.LogOutCallbackPath = "i"; + options.AuthenticationPaths.LogOutFailedPath = "j"; + options.AuthenticationPaths.LogOutSucceededPath = "k"; + options.UserOptions.AuthenticationType = "l"; + options.UserOptions.ScopeClaim = "m"; + options.UserOptions.RoleClaim = "n"; + options.UserOptions.NameClaim = "o"; + options.ProviderOptions.ConfigurationEndpoint = "p"; }); var host = builder.Build(); @@ -298,35 +289,26 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication var builder = new WebAssemblyHostBuilder(new TestWebAssemblyJSRuntimeInvoker()); builder.Services.AddOidcAuthentication(options => { - options.AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions - { - LogInPath = "a", - LogInCallbackPath = "b", - LogInFailedPath = "c", - RegisterPath = "d", - ProfilePath = "e", - RemoteRegisterPath = "f", - RemoteProfilePath = "g", - LogOutPath = "h", - LogOutCallbackPath = "i", - LogOutFailedPath = "j", - LogOutSucceededPath = "k", - }; - options.UserOptions = new RemoteAuthenticationUserOptions - { - AuthenticationType = "l", - ScopeClaim = "m", - RoleClaim = "n", - NameClaim = "o", - }; - options.ProviderOptions = new OidcProviderOptions - { - Authority = "p", - ClientId = "q", - DefaultScopes = Array.Empty(), - RedirectUri = "https://www.example.com/base/custom-login", - PostLogoutRedirectUri = "https://www.example.com/base/custom-logout", - }; + options.AuthenticationPaths.LogInPath = "a"; + options.AuthenticationPaths.LogInCallbackPath = "b"; + options.AuthenticationPaths.LogInFailedPath = "c"; + options.AuthenticationPaths.RegisterPath = "d"; + options.AuthenticationPaths.ProfilePath = "e"; + options.AuthenticationPaths.RemoteRegisterPath = "f"; + options.AuthenticationPaths.RemoteProfilePath = "g"; + options.AuthenticationPaths.LogOutPath = "h"; + options.AuthenticationPaths.LogOutCallbackPath = "i"; + options.AuthenticationPaths.LogOutFailedPath = "j"; + options.AuthenticationPaths.LogOutSucceededPath = "k"; + options.UserOptions.AuthenticationType = "l"; + options.UserOptions.ScopeClaim = "m"; + options.UserOptions.RoleClaim = "n"; + options.UserOptions.NameClaim = "o"; + options.ProviderOptions.Authority = "p"; + options.ProviderOptions.ClientId = "q"; + options.ProviderOptions.DefaultScopes.Clear(); + options.ProviderOptions.RedirectUri = "https://www.example.com/base/custom-login"; + options.ProviderOptions.PostLogoutRedirectUri = "https://www.example.com/base/custom-logout"; }); var host = builder.Build(); diff --git a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/PreferencesUserFactory.cs b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/PreferencesUserFactory.cs index d1bf275264..f9971712fc 100644 --- a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/PreferencesUserFactory.cs +++ b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/PreferencesUserFactory.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal; namespace Wasm.Authentication.Client { - public class PreferencesUserFactory : UserFactory + public class PreferencesUserFactory : AccountClaimsPrincipalFactory { private readonly HttpClient _httpClient; diff --git a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Program.cs b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Program.cs index 80af27b672..da3c29b3a7 100644 --- a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Program.cs +++ b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Program.cs @@ -15,7 +15,7 @@ namespace Wasm.Authentication.Client var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.Services.AddApiAuthorization() - .AddUserFactory(); + .AddAccountClaimsPrincipalFactory(); builder.Services.AddSingleton();