Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jwt 为什么角色声明有时有名称空间,有时没有名称空间_Jwt_Access Token_Identityserver4 - Fatal编程技术网

Jwt 为什么角色声明有时有名称空间,有时没有名称空间

Jwt 为什么角色声明有时有名称空间,有时没有名称空间,jwt,access-token,identityserver4,Jwt,Access Token,Identityserver4,我正在使用IdentityServer4进行身份验证。有些客户端使用引用令牌,有些客户端使用自包含令牌 对于引用令牌,我使用内省客户端交换 用于索赔的accesstokens 对于自包含令牌,我使用“JwtSecurityTokenHandler.ValidateToken”将accesstoken交换为声明 对于第一个,我使用键“role”获取角色声明,对于第二个,我使用键“”获取角色声明 你知道如何在这两种情况下将这一点列为一个关键点吗?你并不是说你的“自包含”客户端使用什么技术,但我假

我正在使用IdentityServer4进行身份验证。有些客户端使用引用令牌,有些客户端使用自包含令牌

  • 对于引用令牌,我使用内省客户端交换 用于索赔的accesstokens
  • 对于自包含令牌,我使用“JwtSecurityTokenHandler.ValidateToken”将accesstoken交换为声明
对于第一个,我使用键“role”获取角色声明,对于第二个,我使用键“”获取角色声明


你知道如何在这两种情况下将这一点列为一个关键点吗?

你并不是说你的“自包含”客户端使用什么技术,但我假设它是某种.NET

以下是解决方案:

.NET核心:

在您的
Startup.cs
(客户端项目)中添加以下行:

JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
对于.NET核心

.NET框架:

再次在
Startup.cs
中添加以下内容:

AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
AntiForgeryConfig.UniqueClaimTypeIdentifier=Constants.ClaimTypes.Subject;
JwtSecurityTokenHandler.InboundClaimTypeMap=new Dictionary();
对于.NET Framework

这将解决您的问题,并且您的所有索赔都将附带简短的名称