- 在项目 XXX.Main.Domain中新建
MyUserClaimsPrincipalFactory
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(AbpUserClaimsPrincipalFactory))] // 替换旧的AbpUserClaimsPrincipalFactory
public class MyUserClaimsPrincipalFactory : AbpUserClaimsPrincipalFactory, IScopedDependency
{
public MainUserClaimsPrincipalFactory(UserManager<IdentityUser> userManager,
RoleManager<IdentityRole> roleManager, IOptions<IdentityOptions> options) :
base(userManager, roleManager, options)
{
}
public override async Task<ClaimsPrincipal> CreateAsync(IdentityUser user)
{
var principal = await base.CreateAsync(user);
var identityPrincipal = principal.Identities.First();
/// add custom claim
/// identityPrincipal.AddClaim(new Claim(XXX, XXX));
return principal;
}
}
- 添加ApiResource
//一般在IdentityServerDataSeedContributor.cs中 添加
private async Task CreateApiResourcesAsync()
{
......
}
- 用的时候
currentUser.FindClaimValue<类型>(ClaimTypes)
网友评论