[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
This commit is contained in:
Javier Calvarro Nelson 2020-04-09 01:08:43 +02:00 committed by GitHub
parent 96e70ebe0e
commit 43bd9dbf3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 129 additions and 155 deletions

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal
/// infrastructure and not subject to the same compatibility standards as public APIs. /// infrastructure and not subject to the same compatibility standards as public APIs.
/// It may be changed or removed without notice in any release. /// It may be changed or removed without notice in any release.
/// </summary> /// </summary>
public interface IRemoteAuthenticationPathsProvider internal interface IRemoteAuthenticationPathsProvider
{ {
/// <summary> /// <summary>
/// This is an internal API that supports the Microsoft.AspNetCore.Components.WebAssembly.Authentication /// This is an internal API that supports the Microsoft.AspNetCore.Components.WebAssembly.Authentication

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
{ {
@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the list of granted scopes for the token. /// Gets or sets the list of granted scopes for the token.
/// </summary> /// </summary>
public string[] GrantedScopes { get; set; } public IReadOnlyList<string> GrantedScopes { get; set; }
/// <summary> /// <summary>
/// Gets the expiration time of the token. /// Gets the expiration time of the token.

View File

@ -6,8 +6,8 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Represents the result of an authentication operation. /// Represents the result of an authentication operation.
/// </summary> /// </summary>
/// <typeparam name="TState">The type of the preserved state during the authentication operation.</typeparam> /// <typeparam name="TRemoteAuthenticationState">The type of the preserved state during the authentication operation.</typeparam>
public class RemoteAuthenticationResult<TState> where TState : class public class RemoteAuthenticationResult<TRemoteAuthenticationState> where TRemoteAuthenticationState : RemoteAuthenticationState
{ {
/// <summary> /// <summary>
/// Gets or sets the status of the authentication operation. The status can be one of <see cref="RemoteAuthenticationStatus"/>. /// Gets or sets the status of the authentication operation. The status can be one of <see cref="RemoteAuthenticationStatus"/>.
@ -22,6 +22,6 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the preserved state of a successful authentication operation. /// Gets or sets the preserved state of a successful authentication operation.
/// </summary> /// </summary>
public TState State { get; set; } public TRemoteAuthenticationState State { get; set; }
} }
} }

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the list of scopes to request when signing in. /// Gets or sets the list of scopes to request when signing in.
/// </summary> /// </summary>
public IList<string> DefaultScopes { get; set; } = new List<string> { "openid", "profile" }; public IList<string> DefaultScopes { get; } = new List<string> { "openid", "profile" };
/// <summary> /// <summary>
/// Gets or sets the redirect uri for the application. The application will be redirected here after the user has completed the sign in /// Gets or sets the redirect uri for the application. The application will be redirected here after the user has completed the sign in

View File

@ -12,16 +12,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the provider options. /// Gets or sets the provider options.
/// </summary> /// </summary>
public TRemoteAuthenticationProviderOptions ProviderOptions { get; set; } = new TRemoteAuthenticationProviderOptions(); public TRemoteAuthenticationProviderOptions ProviderOptions { get; } = new TRemoteAuthenticationProviderOptions();
/// <summary> /// <summary>
/// Gets or sets the <see cref="RemoteAuthenticationApplicationPathsOptions"/>. /// Gets or sets the <see cref="RemoteAuthenticationApplicationPathsOptions"/>.
/// </summary> /// </summary>
public RemoteAuthenticationApplicationPathsOptions AuthenticationPaths { get; set; } = new RemoteAuthenticationApplicationPathsOptions(); public RemoteAuthenticationApplicationPathsOptions AuthenticationPaths { get; } = new RemoteAuthenticationApplicationPathsOptions();
/// <summary> /// <summary>
/// Gets or sets the <see cref="RemoteAuthenticationUserOptions"/>. /// Gets or sets the <see cref="RemoteAuthenticationUserOptions"/>.
/// </summary> /// </summary>
public RemoteAuthenticationUserOptions UserOptions { get; set; } = new RemoteAuthenticationUserOptions(); public RemoteAuthenticationUserOptions UserOptions { get; } = new RemoteAuthenticationUserOptions();
} }
} }

View File

@ -12,44 +12,44 @@ namespace Microsoft.Extensions.DependencyInjection
public static class RemoteAuthenticationBuilderExtensions public static class RemoteAuthenticationBuilderExtensions
{ {
/// <summary> /// <summary>
/// Replaces the existing <see cref="UserFactory{TAccount}"/> with the user factory defined by <typeparamref name="TUserFactory"/>. /// Replaces the existing <see cref="AccountClaimsPrincipalFactory{TAccount}"/> with the user factory defined by <typeparamref name="TAccountClaimsPrincipalFactory"/>.
/// </summary> /// </summary>
/// <typeparam name="TRemoteAuthenticationState">The remote authentication state.</typeparam> /// <typeparam name="TRemoteAuthenticationState">The remote authentication state.</typeparam>
/// <typeparam name="TAccount">The account type.</typeparam> /// <typeparam name="TAccount">The account type.</typeparam>
/// <typeparam name="TUserFactory">The new user factory type.</typeparam> /// <typeparam name="TAccountClaimsPrincipalFactory">The new user factory type.</typeparam>
/// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, TAccount}"/>.</param> /// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, TAccount}"/>.</param>
/// <returns>The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, TAccount}"/>.</returns> /// <returns>The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, TAccount}"/>.</returns>
public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount> AddUserFactory<TRemoteAuthenticationState, TAccount, TUserFactory>( public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount> AddAccountClaimsPrincipalFactory<TRemoteAuthenticationState, TAccount, TAccountClaimsPrincipalFactory>(
this IRemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount> builder) this IRemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount> builder)
where TRemoteAuthenticationState : RemoteAuthenticationState, new() where TRemoteAuthenticationState : RemoteAuthenticationState, new()
where TAccount : RemoteUserAccount where TAccount : RemoteUserAccount
where TUserFactory : UserFactory<TAccount> where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory<TAccount>
{ {
builder.Services.Replace(ServiceDescriptor.Scoped<UserFactory<TAccount>, TUserFactory>()); builder.Services.Replace(ServiceDescriptor.Scoped<AccountClaimsPrincipalFactory<TAccount>, TAccountClaimsPrincipalFactory>());
return builder; return builder;
} }
/// <summary> /// <summary>
/// Replaces the existing <see cref="UserFactory{Account}"/> with the user factory defined by <typeparamref name="TUserFactory"/>. /// Replaces the existing <see cref="AccountClaimsPrincipalFactory{Account}"/> with the user factory defined by <typeparamref name="TAccountClaimsPrincipalFactory"/>.
/// </summary> /// </summary>
/// <typeparam name="TRemoteAuthenticationState">The remote authentication state.</typeparam> /// <typeparam name="TRemoteAuthenticationState">The remote authentication state.</typeparam>
/// <typeparam name="TUserFactory">The new user factory type.</typeparam> /// <typeparam name="TAccountClaimsPrincipalFactory">The new user factory type.</typeparam>
/// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, Account}"/>.</param> /// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, Account}"/>.</param>
/// <returns>The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, Account}"/>.</returns> /// <returns>The <see cref="IRemoteAuthenticationBuilder{TRemoteAuthenticationState, Account}"/>.</returns>
public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, RemoteUserAccount> AddUserFactory<TRemoteAuthenticationState, TUserFactory>( public static IRemoteAuthenticationBuilder<TRemoteAuthenticationState, RemoteUserAccount> AddAccountClaimsPrincipalFactory<TRemoteAuthenticationState, TAccountClaimsPrincipalFactory>(
this IRemoteAuthenticationBuilder<TRemoteAuthenticationState, RemoteUserAccount> builder) this IRemoteAuthenticationBuilder<TRemoteAuthenticationState, RemoteUserAccount> builder)
where TRemoteAuthenticationState : RemoteAuthenticationState, new() where TRemoteAuthenticationState : RemoteAuthenticationState, new()
where TUserFactory : UserFactory<RemoteUserAccount> => builder.AddUserFactory<TRemoteAuthenticationState, RemoteUserAccount, TUserFactory>(); where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory<RemoteUserAccount> => builder.AddAccountClaimsPrincipalFactory<TRemoteAuthenticationState, RemoteUserAccount, TAccountClaimsPrincipalFactory>();
/// <summary> /// <summary>
/// Replaces the existing <see cref="UserFactory{TAccount}"/> with the user factory defined by <typeparamref name="TUserFactory"/>. /// Replaces the existing <see cref="AccountClaimsPrincipalFactory{TAccount}"/> with the user factory defined by <typeparamref name="TAccountClaimsPrincipalFactory"/>.
/// </summary> /// </summary>
/// <typeparam name="TUserFactory">The new user factory type.</typeparam> /// <typeparam name="TAccountClaimsPrincipalFactory">The new user factory type.</typeparam>
/// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{RemoteAuthenticationState, Account}"/>.</param> /// <param name="builder">The <see cref="IRemoteAuthenticationBuilder{RemoteAuthenticationState, Account}"/>.</param>
/// <returns>The <see cref="IRemoteAuthenticationBuilder{RemoteAuthenticationState, Account}"/>.</returns> /// <returns>The <see cref="IRemoteAuthenticationBuilder{RemoteAuthenticationState, Account}"/>.</returns>
public static IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> AddUserFactory<TUserFactory>( public static IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> AddAccountClaimsPrincipalFactory<TAccountClaimsPrincipalFactory>(
this IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> builder) this IRemoteAuthenticationBuilder<RemoteAuthenticationState, RemoteUserAccount> builder)
where TUserFactory : UserFactory<RemoteUserAccount> => builder.AddUserFactory<RemoteAuthenticationState, RemoteUserAccount, TUserFactory>(); where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory<RemoteUserAccount> => builder.AddAccountClaimsPrincipalFactory<RemoteAuthenticationState, RemoteUserAccount, TAccountClaimsPrincipalFactory>();
} }
} }

View File

@ -11,46 +11,46 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// The default login path. /// The default login path.
/// </summary> /// </summary>
public const string LoginPath = "authentication/login"; public static readonly string LoginPath = "authentication/login";
/// <summary> /// <summary>
/// The default login callback path. /// The default login callback path.
/// </summary> /// </summary>
public const string LoginCallbackPath = "authentication/login-callback"; public static readonly string LoginCallbackPath = "authentication/login-callback";
/// <summary> /// <summary>
/// The default login failed path. /// The default login failed path.
/// </summary> /// </summary>
public const string LoginFailedPath = "authentication/login-failed"; public static readonly string LoginFailedPath = "authentication/login-failed";
/// <summary> /// <summary>
/// The default logout path. /// The default logout path.
/// </summary> /// </summary>
public const string LogoutPath = "authentication/logout"; public static readonly string LogoutPath = "authentication/logout";
/// <summary> /// <summary>
/// The default logout callback path. /// The default logout callback path.
/// </summary> /// </summary>
public const string LogoutCallbackPath = "authentication/logout-callback"; public static readonly string LogoutCallbackPath = "authentication/logout-callback";
/// <summary> /// <summary>
/// The default logout failed path. /// The default logout failed path.
/// </summary> /// </summary>
public const string LogoutFailedPath = "authentication/logout-failed"; public static readonly string LogoutFailedPath = "authentication/logout-failed";
/// <summary> /// <summary>
/// The default logout succeeded path. /// The default logout succeeded path.
/// </summary> /// </summary>
public const string LogoutSucceededPath = "authentication/logged-out"; public static readonly string LogoutSucceededPath = "authentication/logged-out";
/// <summary> /// <summary>
/// The default profile path. /// The default profile path.
/// </summary> /// </summary>
public const string ProfilePath = "authentication/profile"; public static readonly string ProfilePath = "authentication/profile";
/// <summary> /// <summary>
/// The default register path. /// The default register path.
/// </summary> /// </summary>
public const string RegisterPath = "authentication/register"; public static readonly string RegisterPath = "authentication/register";
} }
} }

View File

@ -88,34 +88,34 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the <see cref="IJSRuntime"/> to use for performin JavaScript interop. /// Gets or sets the <see cref="IJSRuntime"/> to use for performin JavaScript interop.
/// </summary> /// </summary>
[Inject] public IJSRuntime JS { get; set; } [Inject] internal IJSRuntime JS { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="NavigationManager"/> to use for redirecting the browser. /// Gets or sets the <see cref="NavigationManager"/> to use for redirecting the browser.
/// </summary> /// </summary>
[Inject] public NavigationManager Navigation { get; set; } [Inject] internal NavigationManager Navigation { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="IRemoteAuthenticationService{TRemoteAuthenticationState}"/> to use for handling the underlying authentication protocol. /// Gets or sets the <see cref="IRemoteAuthenticationService{TRemoteAuthenticationState}"/> to use for handling the underlying authentication protocol.
/// </summary> /// </summary>
[Inject] public IRemoteAuthenticationService<TAuthenticationState> AuthenticationService { get; set; } [Inject] internal IRemoteAuthenticationService<TAuthenticationState> AuthenticationService { get; set; }
/// <summary> /// <summary>
/// Gets or sets a default <see cref="IRemoteAuthenticationPathsProvider"/> to use as fallback if an <see cref="ApplicationPaths"/> has not been explicitly specified. /// Gets or sets a default <see cref="IRemoteAuthenticationPathsProvider"/> to use as fallback if an <see cref="ApplicationPaths"/> has not been explicitly specified.
/// </summary> /// </summary>
#pragma warning disable PUB0001 // Pubternal type in public API #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 #pragma warning restore PUB0001 // Pubternal type in public API
/// <summary> /// <summary>
/// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user. /// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user.
/// </summary> /// </summary>
[Inject] public AuthenticationStateProvider AuthenticationProvider { get; set; } [Inject] internal AuthenticationStateProvider AuthenticationProvider { get; set; }
/// <summary> /// <summary>
/// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user. /// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user.
/// </summary> /// </summary>
[Inject] public SignOutSessionStateManager SignOutManager { get; set; } [Inject] internal SignOutSessionStateManager SignOutManager { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="RemoteAuthenticationApplicationPathsOptions"/> with the paths to different authentication pages. /// Gets or sets the <see cref="RemoteAuthenticationApplicationPathsOptions"/> with the paths to different authentication pages.

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the list of scopes to request for the token. /// Gets or sets the list of scopes to request for the token.
/// </summary> /// </summary>
public string[] Scopes { get; set; } public IEnumerable<string> Scopes { get; set; }
/// <summary> /// <summary>
/// Gets or sets a specific return url to use for returning the user back to the application if it needs to be /// Gets or sets a specific return url to use for returning the user back to the application if it needs to be

View File

@ -28,12 +28,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary> /// <summary>
/// Gets or sets the status of the current operation. See <see cref="AccessTokenResultStatus"/> for a list of statuses. /// Gets or sets the status of the current operation. See <see cref="AccessTokenResultStatus"/> for a list of statuses.
/// </summary> /// </summary>
public AccessTokenResultStatus Status { get; set; } public AccessTokenResultStatus Status { get; }
/// <summary> /// <summary>
/// Gets or sets the URL to redirect to if <see cref="Status"/> is <see cref="AccessTokenResultStatus.RequiresRedirect"/>. /// Gets or sets the URL to redirect to if <see cref="Status"/> is <see cref="AccessTokenResultStatus.RequiresRedirect"/>.
/// </summary> /// </summary>
public string RedirectUrl { get; set; } public string RedirectUrl { get; }
/// <summary> /// <summary>
/// Determines whether the token request was successful and makes the <see cref="AccessToken"/> available for use when it is. /// Determines whether the token request was successful and makes the <see cref="AccessToken"/> available for use when it is.

View File

@ -12,12 +12,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// Converts <see cref="RemoteUserAccount" /> into a <see cref="ClaimsPrincipal"/>. /// Converts <see cref="RemoteUserAccount" /> into a <see cref="ClaimsPrincipal"/>.
/// </summary> /// </summary>
/// <typeparam name="TAccount">The account type.</typeparam> /// <typeparam name="TAccount">The account type.</typeparam>
public class UserFactory<TAccount> where TAccount : RemoteUserAccount public class AccountClaimsPrincipalFactory<TAccount> where TAccount : RemoteUserAccount
{ {
private readonly IAccessTokenProviderAccessor _accessor; private readonly IAccessTokenProviderAccessor _accessor;
#pragma warning disable PUB0001 // Pubternal type in public API #pragma warning disable PUB0001 // Pubternal type in public API
public UserFactory(IAccessTokenProviderAccessor accessor) => _accessor = accessor; public AccountClaimsPrincipalFactory(IAccessTokenProviderAccessor accessor) => _accessor = accessor;
/// <summary> /// <summary>
/// Gets or sets the <see cref="IAccessTokenProvider"/>. /// Gets or sets the <see cref="IAccessTokenProvider"/>.

View File

@ -43,9 +43,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
protected NavigationManager Navigation { get; } protected NavigationManager Navigation { get; }
/// <summary> /// <summary>
/// Gets the <see cref="UserFactory{TAccount}"/> to map accounts to <see cref="ClaimsPrincipal"/>. /// Gets the <see cref="AccountClaimsPrincipalFactory{TAccount}"/> to map accounts to <see cref="ClaimsPrincipal"/>.
/// </summary> /// </summary>
protected UserFactory<TAccount> UserFactory { get; } protected AccountClaimsPrincipalFactory<TAccount> AccountClaimsPrincipalFactory { get; }
/// <summary> /// <summary>
/// Gets the options for the underlying JavaScript library handling the authentication operations. /// Gets the options for the underlying JavaScript library handling the authentication operations.
@ -58,16 +58,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <param name="jsRuntime">The <see cref="IJSRuntime"/> to use for performing JavaScript interop operations.</param> /// <param name="jsRuntime">The <see cref="IJSRuntime"/> to use for performing JavaScript interop operations.</param>
/// <param name="options">The options to be passed down to the underlying JavaScript library handling the authentication operations.</param> /// <param name="options">The options to be passed down to the underlying JavaScript library handling the authentication operations.</param>
/// <param name="navigation">The <see cref="NavigationManager"/> used to generate URLs.</param> /// <param name="navigation">The <see cref="NavigationManager"/> used to generate URLs.</param>
/// <param name="userFactory">The <see cref="UserFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param> /// <param name="accountClaimsPrincipalFactory">The <see cref="AccountClaimsPrincipalFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param>
public RemoteAuthenticationService( public RemoteAuthenticationService(
IJSRuntime jsRuntime, IJSRuntime jsRuntime,
IOptions<RemoteAuthenticationOptions<TProviderOptions>> options, IOptions<RemoteAuthenticationOptions<TProviderOptions>> options,
NavigationManager navigation, NavigationManager navigation,
UserFactory<TAccount> userFactory) AccountClaimsPrincipalFactory<TAccount> accountClaimsPrincipalFactory)
{ {
JsRuntime = jsRuntime; JsRuntime = jsRuntime;
Navigation = navigation; Navigation = navigation;
UserFactory = userFactory; AccountClaimsPrincipalFactory = accountClaimsPrincipalFactory;
Options = options.Value; Options = options.Value;
} }
@ -217,7 +217,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
{ {
await EnsureAuthService(); await EnsureAuthService();
var account = await JsRuntime.InvokeAsync<TAccount>("AuthenticationService.getUser"); var account = await JsRuntime.InvokeAsync<TAccount>("AuthenticationService.getUser");
var user = await UserFactory.CreateUserAsync(account, Options.UserOptions); var user = await AccountClaimsPrincipalFactory.CreateUserAsync(account, Options.UserOptions);
return user; return user;
} }

View File

@ -47,7 +47,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.TryAddScoped<IAccessTokenProviderAccessor, AccessTokenProviderAccessor>(); services.TryAddScoped<IAccessTokenProviderAccessor, AccessTokenProviderAccessor>();
services.TryAddScoped<SignOutSessionStateManager>(); services.TryAddScoped<SignOutSessionStateManager>();
services.TryAddScoped<UserFactory<TAccount>>(); services.TryAddScoped<AccountClaimsPrincipalFactory<TAccount>>();
return new RemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount>(services); return new RemoteAuthenticationBuilder<TRemoteAuthenticationState, TAccount>(services);
} }

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState> testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -260,7 +260,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult
@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult
@ -338,7 +338,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState(); var state = new RemoteAuthenticationState();
testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult
@ -379,7 +379,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())); new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
testJsRuntime.GetUserResult = default; testJsRuntime.GetUserResult = default;
@ -406,7 +406,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new TestUserFactory(Mock.Of<IAccessTokenProviderAccessor>())); new TestAccountClaimsPrincipalFactory(Mock.Of<IAccessTokenProviderAccessor>()));
var account = new CoolRoleAccount var account = new CoolRoleAccount
{ {
@ -442,7 +442,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime, testJsRuntime,
options, options,
new TestNavigationManager(), new TestNavigationManager(),
new TestUserFactory(Mock.Of<IAccessTokenProviderAccessor>())); new TestAccountClaimsPrincipalFactory(Mock.Of<IAccessTokenProviderAccessor>()));
var account = new CoolRoleAccount var account = new CoolRoleAccount
{ {
@ -481,39 +481,30 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
private static IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> CreateOptions(string scopeClaim = null) private static IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> CreateOptions(string scopeClaim = null)
{ {
return Options.Create( var options = new RemoteAuthenticationOptions<OidcProviderOptions>();
new RemoteAuthenticationOptions<OidcProviderOptions>()
{ options.AuthenticationPaths.LogInPath = "login";
AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions options.AuthenticationPaths.LogInCallbackPath = "a";
{ options.AuthenticationPaths.LogInFailedPath = "a";
LogInPath = "login", options.AuthenticationPaths.RegisterPath = "a";
LogInCallbackPath = "a", options.AuthenticationPaths.ProfilePath = "a";
LogInFailedPath = "a", options.AuthenticationPaths.RemoteRegisterPath = "a";
RegisterPath = "a", options.AuthenticationPaths.RemoteProfilePath = "a";
ProfilePath = "a", options.AuthenticationPaths.LogOutPath = "a";
RemoteRegisterPath = "a", options.AuthenticationPaths.LogOutCallbackPath = "a";
RemoteProfilePath = "a", options.AuthenticationPaths.LogOutFailedPath = "a";
LogOutPath = "a", options.AuthenticationPaths.LogOutSucceededPath = "a";
LogOutCallbackPath = "a", options.UserOptions.AuthenticationType = "a";
LogOutFailedPath = "a", options.UserOptions.ScopeClaim = scopeClaim;
LogOutSucceededPath = "a", options.UserOptions.RoleClaim = "coolRole";
}, options.UserOptions.NameClaim = "coolName";
UserOptions = new RemoteAuthenticationUserOptions options.ProviderOptions.Authority = "a";
{ options.ProviderOptions.ClientId = "a";
AuthenticationType = "a", options.ProviderOptions.DefaultScopes.Add("openid");
ScopeClaim = scopeClaim, options.ProviderOptions.RedirectUri = "https://www.example.com/base/custom-login";
RoleClaim = "coolRole", options.ProviderOptions.PostLogoutRedirectUri = "https://www.example.com/base/custom-logout";
NameClaim = "coolName",
}, return Options.Create(options);
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",
}
});
} }
private class TestJsRuntime : IJSRuntime private class TestJsRuntime : IJSRuntime
@ -571,9 +562,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
} }
} }
internal class TestUserFactory : UserFactory<CoolRoleAccount> internal class TestAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory<CoolRoleAccount>
{ {
public TestUserFactory(IAccessTokenProviderAccessor accessor) : base(accessor) public TestAccountClaimsPrincipalFactory(IAccessTokenProviderAccessor accessor) : base(accessor)
{ {
} }

View File

@ -667,7 +667,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
IJSRuntime jsRuntime, IJSRuntime jsRuntime,
IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> options, IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> options,
TestNavigationManager navigationManager) : TestNavigationManager navigationManager) :
base(jsRuntime, options, navigationManager, new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>())) base(jsRuntime, options, navigationManager, new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()))
{ {
} }

View File

@ -200,31 +200,22 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
var builder = new WebAssemblyHostBuilder(new TestWebAssemblyJSRuntimeInvoker()); var builder = new WebAssemblyHostBuilder(new TestWebAssemblyJSRuntimeInvoker());
builder.Services.AddApiAuthorization(options => builder.Services.AddApiAuthorization(options =>
{ {
options.AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions options.AuthenticationPaths.LogInPath = "a";
{ options.AuthenticationPaths.LogInCallbackPath = "b";
LogInPath = "a", options.AuthenticationPaths.LogInFailedPath = "c";
LogInCallbackPath = "b", options.AuthenticationPaths.RegisterPath = "d";
LogInFailedPath = "c", options.AuthenticationPaths.ProfilePath = "e";
RegisterPath = "d", options.AuthenticationPaths.RemoteRegisterPath = "f";
ProfilePath = "e", options.AuthenticationPaths.RemoteProfilePath = "g";
RemoteRegisterPath = "f", options.AuthenticationPaths.LogOutPath = "h";
RemoteProfilePath = "g", options.AuthenticationPaths.LogOutCallbackPath = "i";
LogOutPath = "h", options.AuthenticationPaths.LogOutFailedPath = "j";
LogOutCallbackPath = "i", options.AuthenticationPaths.LogOutSucceededPath = "k";
LogOutFailedPath = "j", options.UserOptions.AuthenticationType = "l";
LogOutSucceededPath = "k", options.UserOptions.ScopeClaim = "m";
}; options.UserOptions.RoleClaim = "n";
options.UserOptions = new RemoteAuthenticationUserOptions options.UserOptions.NameClaim = "o";
{ options.ProviderOptions.ConfigurationEndpoint = "p";
AuthenticationType = "l",
ScopeClaim = "m",
RoleClaim = "n",
NameClaim = "o",
};
options.ProviderOptions = new ApiAuthorizationProviderOptions
{
ConfigurationEndpoint = "p"
};
}); });
var host = builder.Build(); var host = builder.Build();
@ -298,35 +289,26 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
var builder = new WebAssemblyHostBuilder(new TestWebAssemblyJSRuntimeInvoker()); var builder = new WebAssemblyHostBuilder(new TestWebAssemblyJSRuntimeInvoker());
builder.Services.AddOidcAuthentication(options => builder.Services.AddOidcAuthentication(options =>
{ {
options.AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions options.AuthenticationPaths.LogInPath = "a";
{ options.AuthenticationPaths.LogInCallbackPath = "b";
LogInPath = "a", options.AuthenticationPaths.LogInFailedPath = "c";
LogInCallbackPath = "b", options.AuthenticationPaths.RegisterPath = "d";
LogInFailedPath = "c", options.AuthenticationPaths.ProfilePath = "e";
RegisterPath = "d", options.AuthenticationPaths.RemoteRegisterPath = "f";
ProfilePath = "e", options.AuthenticationPaths.RemoteProfilePath = "g";
RemoteRegisterPath = "f", options.AuthenticationPaths.LogOutPath = "h";
RemoteProfilePath = "g", options.AuthenticationPaths.LogOutCallbackPath = "i";
LogOutPath = "h", options.AuthenticationPaths.LogOutFailedPath = "j";
LogOutCallbackPath = "i", options.AuthenticationPaths.LogOutSucceededPath = "k";
LogOutFailedPath = "j", options.UserOptions.AuthenticationType = "l";
LogOutSucceededPath = "k", options.UserOptions.ScopeClaim = "m";
}; options.UserOptions.RoleClaim = "n";
options.UserOptions = new RemoteAuthenticationUserOptions options.UserOptions.NameClaim = "o";
{ options.ProviderOptions.Authority = "p";
AuthenticationType = "l", options.ProviderOptions.ClientId = "q";
ScopeClaim = "m", options.ProviderOptions.DefaultScopes.Clear();
RoleClaim = "n", options.ProviderOptions.RedirectUri = "https://www.example.com/base/custom-login";
NameClaim = "o", options.ProviderOptions.PostLogoutRedirectUri = "https://www.example.com/base/custom-logout";
};
options.ProviderOptions = new OidcProviderOptions
{
Authority = "p",
ClientId = "q",
DefaultScopes = Array.Empty<string>(),
RedirectUri = "https://www.example.com/base/custom-login",
PostLogoutRedirectUri = "https://www.example.com/base/custom-logout",
};
}); });
var host = builder.Build(); var host = builder.Build();

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal;
namespace Wasm.Authentication.Client namespace Wasm.Authentication.Client
{ {
public class PreferencesUserFactory : UserFactory<OidcAccount> public class PreferencesUserFactory : AccountClaimsPrincipalFactory<OidcAccount>
{ {
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;

View File

@ -15,7 +15,7 @@ namespace Wasm.Authentication.Client
var builder = WebAssemblyHostBuilder.CreateDefault(args); var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddApiAuthorization<RemoteAppState, OidcAccount>() builder.Services.AddApiAuthorization<RemoteAppState, OidcAccount>()
.AddUserFactory<RemoteAppState, OidcAccount, PreferencesUserFactory>(); .AddAccountClaimsPrincipalFactory<RemoteAppState, OidcAccount, PreferencesUserFactory>();
builder.Services.AddSingleton<StateService>(); builder.Services.AddSingleton<StateService>();