[EDIT by guardrex to add topic metadata]
Content
Steps for customizing the user bound to the application.
- Create a class
YourAccount that extends the Account class.
public class YourAccount : Account
{
[JsonPropertyName("amr")]
public string[] AuthenticationMethod { get; set; }
}
- Create a class
YourUserFactory that extends AccountClaimsPrincipalFactory<YourAccount>
public class YourAccountFactory : AccountClaimsPrincipalFactory<OidcAccount>
{
public AccountClaimsPrincipalFactory(NavigationManager navigationManager, IAccessTokenProviderAccessor accessor)
: base(accessor)
{
}
public async override ValueTask<ClaimsPrincipal> CreateUserAsync(
OidcAccount account,
RemoteAuthenticationUserOptions options)
{
var initialUser = await base.CreateUserAsync(account, options);
if (initialUser.Identity.IsAuthenticated)
{
foreach (var value in account.AuthenticationMethod)
{
((ClaimsIdentity)initialUser.Identity).AddClaim(new Claim("amr", value));
}
}
}
}
- Call
services.AddApiAuthorization<RemoteAuthenticationState, YourAccount>()
.AddUserFactory<RemoteAuthenticationState, YourAccount, YourUserFactory>();
Document details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
[EDIT by guardrex to add topic metadata]
Content
Steps for customizing the user bound to the application.
YourAccountthat extends the Account class.YourUserFactorythat extendsAccountClaimsPrincipalFactory<YourAccount>Document details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.