Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.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
C# 解码Azure移动服务JWT令牌时发生JwtSecurityToken异常_C#_Azure_Azure Mobile Services_Federated Identity_Jwt - Fatal编程技术网

C# 解码Azure移动服务JWT令牌时发生JwtSecurityToken异常

C# 解码Azure移动服务JWT令牌时发生JwtSecurityToken异常,c#,azure,azure-mobile-services,federated-identity,jwt,C#,Azure,Azure Mobile Services,Federated Identity,Jwt,以下代码: using System.IdentityModel.Tokens; JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(rawToken); 生成以下异常: Jwt10113: Unable to decode the 'header' The value "0" is not of type "System.String" and cannot be used in this generic collection.

以下代码:

using System.IdentityModel.Tokens;

JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(rawToken);
生成以下异常:

Jwt10113: Unable to decode the 'header'
The value "0" is not of type "System.String" and cannot be used in this generic collection. Parameter name: value
当rawToken的“header”部分为:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6MH0
可解码为:

{"alg":"HS256","typ":"JWT","kid":0}
{"alg":"HS256","typ":"JWT","kid":"0"}
故障令牌的来源是Azure移动服务

请注意,调用同一行代码时,如果“header”部分为:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjAifQ
可解码为:

{"alg":"HS256","typ":"JWT","kid":0}
{"alg":"HS256","typ":"JWT","kid":"0"}

如何克服这个问题,并正确验证这样的令牌?

这是Azure移动服务中的一个bug,它与JWT规范的一致性有关。该bug已经修复,因此移动服务生成的JWT现在应该在“kid”中有一个正确的字符串值标题字段。

Azure移动服务生成的令牌中目前存在一个与JWT规范一致性相关的缺陷。这应该在其即将发布的版本中修复。感谢@carlosfigueira,你可以指向文档或问题页面的链接吗?只是更新:此错误已修复-Azure移动服务生成的JWT现在在标题中将“kid”字段设置为字符串值。听起来很有希望!谢谢回到这篇文章。我会尽快查出来,然后告诉你。