美文网首页
abp vnext 扩展 ICurrentUser,登录时增加C

abp vnext 扩展 ICurrentUser,登录时增加C

作者: tky753 | 来源:发表于2019-11-12 05:54 被阅读0次
    1. 在项目 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;
        }
    }
    
    1. 添加ApiResource
    //一般在IdentityServerDataSeedContributor.cs中 添加
    private async Task CreateApiResourcesAsync()
    {
    ......
    }
    
    1. 用的时候
    currentUser.FindClaimValue<类型>(ClaimTypes)
    

    相关文章

      网友评论

          本文标题:abp vnext 扩展 ICurrentUser,登录时增加C

          本文链接:https://www.haomeiwen.com/subject/tpxfictx.html