ASP.NET核心标识和身份服务器4 - [角色,声明和身份资源]
我想问你澄清当IdentityServer 4与ASP.NET身份集成。ASP.NET核心标识和身份服务器4 - [角色,声明和身份资源]
我正在处理两个数据库上下文。 Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext<IdentityUser>
和IdentityServer4.EntityFramework.DbContexts.ConfigurationDbContext
。
Identity Server 4正在使用AspNetIdentity .AddAspNetIdentity<IdentityUser>()
。
所以IdentityUser
已经分配了IdentityUserClaims
,并且在成功验证之后它在JWT令牌中得到了正确的反映。
现在的问题是,来自IdentityServer4的IdentityResource
和IdentityClaim:UserClaim
是什么ConfigurationDbContext
?由于现在从aspnet身份使用声明,因此完全不使用此实体。我对吗?
另一个问题是ApiScopeClaims
如何在游戏中?它们仍然由Identity Server使用,因为ApiScope
为其颁发了令牌。对?但现在我要保持同步ApiScopeClaim
和IdentityUserClaim
这是来自不同的数据库上下文。
最后一个问题是关于IdentityRoles
和IdentityRoleClaims
,它们与IdentityUserClaims
不一样。背后有什么想法?在我的想法中,角色是针对特定业务角色的索赔分组,以便于管理,因此角色不应定义新索赔,但应参考IdentityUserClaims
。另外,我创建了分配给用户的角色,分配给范围的相应索赔类型,结果是 - 分配给角色和用户的索赔具有此角色,但未包含在JWT中。为什么?
谢谢你的回答。
IdentityResource
是一类或一组索赔。每个IdentityResource
可以有许多IdentityClaims
,它们是对AspNetUserClaims
中的实际索赔的参考。内置的IdentityResources
是openid和profile。
ApiScopeClaims是API资源的分级结构的一部分(而不是上面提到的身份资源。)
ApiResource --has many--> ApiScopes --has many--> ApiScopeClaims.
添加权利要求类型的ApiScopeClaim
将附加一个AspNetUserClaim
(如果有的话)到access_token
当用户向ApiScope
发出请求时。
一个IdentityRoleClaim
(即AspNetRoleClaim
)只是一个信息,你可以就一个特定的角色加以解决;它与用户无关,而仅与角色本身有关。
听起来像您想为您的逻辑分组索赔创建一个IdentityResource
,然后在IdentityClaims
中定义这些索赔类型。但是,您需要一种方法来首先找出用户的角色,以便请求scope
参数中适当的IdentityResource
。或者实施其中一个IdentityServer接口,如IProfileService
以在IdentityServer实例上执行此类工作。
它是如何与'IdentityRoleClaims'?它们是'AspNetIdentity'的一部分,但它们是否包含在由IdentityServer4发布的JWT令牌中?我尝试过,但他们不包括在内,也没有角色要求。 –
当API资源需要声明“角色”时,角色包含在适当的值中。但如何包括角色声明? –
将“角色”声明类型添加到“openid”身份资源 –