You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
using APP.Models;
|
|
using BWPMModels;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.Options;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace APP.Helper
|
|
{
|
|
public class CustomClaimsPrincipal : UserClaimsPrincipalFactory<AppUser>
|
|
{
|
|
private readonly UserManager<AppUser> _userManger;
|
|
public CustomClaimsPrincipal(UserManager<AppUser> userManager, IOptions<IdentityOptions> optionsAccessor) : base(userManager, optionsAccessor)
|
|
{
|
|
_userManger = userManager;
|
|
}
|
|
|
|
public override async Task<ClaimsPrincipal> CreateAsync(AppUser user)
|
|
{
|
|
try
|
|
{
|
|
var principal = await base.CreateAsync(user);
|
|
((ClaimsIdentity)principal.Identity).AddClaims(new[]
|
|
{
|
|
new Claim("Id", user.Id.ToString()),
|
|
new Claim("Email", user.Email),
|
|
new Claim("DisplayName", user.FullName ?? user.Email),
|
|
new Claim("Avatar", user.Avatar ?? string.Empty),
|
|
});
|
|
return principal;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|