Gre*_*Gum 4 claims-based-identity asp.net-identity asp.net-core
在 ASPNetCore 中命名声明的基于标准的方法是什么?
例如,我正在使用以下内容创建 JWT,但我想从中取出字符串。
var claims = new[]
{
new Claim("UserName", user.UserName),
new Claim("UserId", user.Id),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim("AppUserId", appUser.Id.ToString()),
new Claim("TenantId", user.TenantId.ToString())
};
Run Code Online (Sandbox Code Playgroud)
似乎有两个不同的 dotnetcore 类:
`System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames`
`System.Security.Claims.ClaimTypes`
Run Code Online (Sandbox Code Playgroud)
我应该使用哪些?
JwtRegisteredClaimNames 看起来像这样:public const string Sub = "sub";
而 ClaimTypes 看起来像这样: public const string Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name ";
我不知道什么时候不同。为什么在第二种情况下使用 url?
通常,Dotnet 框架和 Dotnetcore 中的身份表示都使用System.Security.Claims.ClaimTypes枚举。声明类型字符串来自 WS-* 时代和 Windows Identity Foundation。我认为它不会因向后兼容性而改变。
System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames 代表来自较新协议的声明类型。
因此,如果您使用较新的协议(OAuth、OpenId Connect),您也可以使用JwtRegisteredClaimNames。有时您可能需要在两种声明类型之间进行映射。
此外,sub通常是唯一标识符,因为没有像您可以使用的名称FamilyName或 的唯一属性GivenName。
您也可以定义自己的声明类型。
| 归档时间: |
|
| 查看次数: |
3898 次 |
| 最近记录: |