解码Azure移动服务JWT令牌时出现JwtSecurityTokenexception
以下代码:
using System.IdentityModel.Tokens; JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(rawToken);
生成以下exception:
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
。
请注意,调用同一行代码时不会发生exception,而’header’部分是:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjAifQ
哪个可以解码为:
{"alg":"HS256","typ":"JWT","kid":"0"}
我如何克服这个问题,并正确validation这样的令牌?
这是Azure移动服务中与JWT规范一致的错误。 此错误已被修复,因此移动服务生成的JWT现在应该在其标题的“kid”字段中具有正确的字符串值。