-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomAccountFactory.cs
26 lines (22 loc) · 1.01 KB
/
CustomAccountFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal;
namespace GoogleAuthOIDC
{
public class CustomAccountFactory : AccountClaimsPrincipalFactory<CustomUserAccount>
{
public CustomAccountFactory(IAccessTokenProviderAccessor accessor) : base(accessor)
{ }
public override async ValueTask<ClaimsPrincipal> CreateUserAsync(CustomUserAccount account, RemoteAuthenticationUserOptions options)
{
var initialUser = await base.CreateUserAsync(account, options);
if (initialUser.Identity.IsAuthenticated)
{
((ClaimsIdentity)initialUser.Identity).AddClaim(new Claim(ClaimTypes.Email, account.Email));
((ClaimsIdentity)initialUser.Identity).AddClaim(new Claim(ClaimTypes.Uri, account.Picture, ClaimValueTypes.String));
}
return initialUser;
}
}
}