[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.
/// It may be changed or removed without notice in any release.
/// </summary>
public interface IRemoteAuthenticationPathsProvider
internal interface IRemoteAuthenticationPathsProvider
{
/// <summary>
/// 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.
using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
{
@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary>
/// Gets or sets the list of granted scopes for the token.
/// </summary>
public string[] GrantedScopes { get; set; }
public IReadOnlyList<string> GrantedScopes { get; set; }
/// <summary>
/// Gets the expiration time of the token.

View File

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

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
/// <summary>
/// Gets or sets the list of scopes to request when signing in.
/// </summary>
public IList<string> DefaultScopes { get; set; } = new List<string> { "openid", "profile" };
public IList<string> DefaultScopes { get; } = new List<string> { "openid", "profile" };
/// <summary>
/// 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>
/// Gets or sets the provider options.
/// </summary>
public TRemoteAuthenticationProviderOptions ProviderOptions { get; set; } = new TRemoteAuthenticationProviderOptions();
public TRemoteAuthenticationProviderOptions ProviderOptions { get; } = new TRemoteAuthenticationProviderOptions();
/// <summary>
/// Gets or sets the <see cref="RemoteAuthenticationApplicationPathsOptions"/>.
/// </summary>
public RemoteAuthenticationApplicationPathsOptions AuthenticationPaths { get; set; } = new RemoteAuthenticationApplicationPathsOptions();
public RemoteAuthenticationApplicationPathsOptions AuthenticationPaths { get; } = new RemoteAuthenticationApplicationPathsOptions();
/// <summary>
/// Gets or sets the <see cref="RemoteAuthenticationUserOptions"/>.
/// </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
{
/// <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>
/// <typeparam name="TRemoteAuthenticationState">The remote authentication state.</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>
/// <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)
where TRemoteAuthenticationState : RemoteAuthenticationState, new()
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;
}
/// <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>
/// <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>
/// <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)
where TRemoteAuthenticationState : RemoteAuthenticationState, new()
where TUserFactory : UserFactory<RemoteUserAccount> => builder.AddUserFactory<TRemoteAuthenticationState, RemoteUserAccount, TUserFactory>();
where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory<RemoteUserAccount> => builder.AddAccountClaimsPrincipalFactory<TRemoteAuthenticationState, RemoteUserAccount, TAccountClaimsPrincipalFactory>();
/// <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>
/// <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>
/// <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)
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>
/// The default login path.
/// </summary>
public const string LoginPath = "authentication/login";
public static readonly string LoginPath = "authentication/login";
/// <summary>
/// The default login callback path.
/// </summary>
public const string LoginCallbackPath = "authentication/login-callback";
public static readonly string LoginCallbackPath = "authentication/login-callback";
/// <summary>
/// The default login failed path.
/// </summary>
public const string LoginFailedPath = "authentication/login-failed";
public static readonly string LoginFailedPath = "authentication/login-failed";
/// <summary>
/// The default logout path.
/// </summary>
public const string LogoutPath = "authentication/logout";
public static readonly string LogoutPath = "authentication/logout";
/// <summary>
/// The default logout callback path.
/// </summary>
public const string LogoutCallbackPath = "authentication/logout-callback";
public static readonly string LogoutCallbackPath = "authentication/logout-callback";
/// <summary>
/// The default logout failed path.
/// </summary>
public const string LogoutFailedPath = "authentication/logout-failed";
public static readonly string LogoutFailedPath = "authentication/logout-failed";
/// <summary>
/// The default logout succeeded path.
/// </summary>
public const string LogoutSucceededPath = "authentication/logged-out";
public static readonly string LogoutSucceededPath = "authentication/logged-out";
/// <summary>
/// The default profile path.
/// </summary>
public const string ProfilePath = "authentication/profile";
public static readonly string ProfilePath = "authentication/profile";
/// <summary>
/// The default register path.
/// </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>
/// Gets or sets the <see cref="IJSRuntime"/> to use for performin JavaScript interop.
/// </summary>
[Inject] public IJSRuntime JS { get; set; }
[Inject] internal IJSRuntime JS { get; set; }
/// <summary>
/// Gets or sets the <see cref="NavigationManager"/> to use for redirecting the browser.
/// </summary>
[Inject] public NavigationManager Navigation { get; set; }
[Inject] internal NavigationManager Navigation { get; set; }
/// <summary>
/// Gets or sets the <see cref="IRemoteAuthenticationService{TRemoteAuthenticationState}"/> to use for handling the underlying authentication protocol.
/// </summary>
[Inject] public IRemoteAuthenticationService<TAuthenticationState> AuthenticationService { get; set; }
[Inject] internal IRemoteAuthenticationService<TAuthenticationState> AuthenticationService { get; set; }
/// <summary>
/// Gets or sets a default <see cref="IRemoteAuthenticationPathsProvider"/> to use as fallback if an <see cref="ApplicationPaths"/> has not been explicitly specified.
/// </summary>
#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
/// <summary>
/// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user.
/// </summary>
[Inject] public AuthenticationStateProvider AuthenticationProvider { get; set; }
[Inject] internal AuthenticationStateProvider AuthenticationProvider { get; set; }
/// <summary>
/// Gets or sets a default <see cref="AuthenticationStateProvider"/> with the current user.
/// </summary>
[Inject] public SignOutSessionStateManager SignOutManager { get; set; }
[Inject] internal SignOutSessionStateManager SignOutManager { get; set; }
/// <summary>
/// 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>
/// Gets or sets the list of scopes to request for the token.
/// </summary>
public string[] Scopes { get; set; }
public IEnumerable<string> Scopes { get; set; }
/// <summary>
/// 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>
/// Gets or sets the status of the current operation. See <see cref="AccessTokenResultStatus"/> for a list of statuses.
/// </summary>
public AccessTokenResultStatus Status { get; set; }
public AccessTokenResultStatus Status { get; }
/// <summary>
/// Gets or sets the URL to redirect to if <see cref="Status"/> is <see cref="AccessTokenResultStatus.RequiresRedirect"/>.
/// </summary>
public string RedirectUrl { get; set; }
public string RedirectUrl { get; }
/// <summary>
/// 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"/>.
/// </summary>
/// <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;
#pragma warning disable PUB0001 // Pubternal type in public API
public UserFactory(IAccessTokenProviderAccessor accessor) => _accessor = accessor;
public AccountClaimsPrincipalFactory(IAccessTokenProviderAccessor accessor) => _accessor = accessor;
/// <summary>
/// Gets or sets the <see cref="IAccessTokenProvider"/>.

View File

@ -43,9 +43,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
protected NavigationManager Navigation { get; }
/// <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>
protected UserFactory<TAccount> UserFactory { get; }
protected AccountClaimsPrincipalFactory<TAccount> AccountClaimsPrincipalFactory { get; }
/// <summary>
/// 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="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="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(
IJSRuntime jsRuntime,
IOptions<RemoteAuthenticationOptions<TProviderOptions>> options,
NavigationManager navigation,
UserFactory<TAccount> userFactory)
AccountClaimsPrincipalFactory<TAccount> 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<TAccount>("AuthenticationService.getUser");
var user = await UserFactory.CreateUserAsync(account, Options.UserOptions);
var user = await AccountClaimsPrincipalFactory.CreateUserAsync(account, Options.UserOptions);
return user;
}

View File

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

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.SignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignInResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.SignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.CompleteSignOutResult = new InternalRemoteAuthenticationResult<RemoteAuthenticationState>
@ -260,7 +260,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult
@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult
@ -338,7 +338,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
var state = new RemoteAuthenticationState();
testJsRuntime.GetAccessTokenResult = new InternalAccessTokenResult
@ -379,7 +379,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new UserFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()));
testJsRuntime.GetUserResult = default;
@ -406,7 +406,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new TestUserFactory(Mock.Of<IAccessTokenProviderAccessor>()));
new TestAccountClaimsPrincipalFactory(Mock.Of<IAccessTokenProviderAccessor>()));
var account = new CoolRoleAccount
{
@ -442,7 +442,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
testJsRuntime,
options,
new TestNavigationManager(),
new TestUserFactory(Mock.Of<IAccessTokenProviderAccessor>()));
new TestAccountClaimsPrincipalFactory(Mock.Of<IAccessTokenProviderAccessor>()));
var account = new CoolRoleAccount
{
@ -481,39 +481,30 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
private static IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> CreateOptions(string scopeClaim = null)
{
return Options.Create(
new RemoteAuthenticationOptions<OidcProviderOptions>()
{
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<OidcProviderOptions>();
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<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,
IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> options,
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());
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<string>(),
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();

View File

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

View File

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