【发布时间】:2013-08-18 21:17:45
【问题描述】:
以下代码:
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}
错误令牌的来源是Azure Mobile Services。
请注意,当'header'部分是:调用同一行代码时不会发生异常:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjAifQ
可以解码为:
{"alg":"HS256","typ":"JWT","kid":"0"}
我怎样才能克服这个问题,并正确验证这样的令牌?
【问题讨论】:
-
Azure 移动服务生成的令牌中目前存在与 JWT 规范的一致性相关的错误。这应该在其即将发布的版本之一中得到解决。
-
谢谢@carlosfigueira,你能指出一个文档或问题页面的链接吗?
-
只是一个更新:此错误已得到修复 - Azure 移动服务生成的 JWT 现在在其标头中将“kid”字段设置为字符串值。
标签: c# azure azure-mobile-services federated-identity jwt