以下代码:
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}
错误 token 的来源是 Azure 移动服务
。
请注意,当“header”部分为:时调用同一行代码时,不会发生异常:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjAifQ
可以解码为:
{"alg":"HS256","typ":"JWT","kid":"0"}
我怎样才能克服这个问题,并正确验证这样的 token ?
最佳答案
这是 Azure 移动服务中与 JWT 规范的一致性有关的错误。该错误现已修复,因此移动服务生成的 JWT 现在应在其 header 的“kid”字段中具有正确的字符串值。
关于c# - 解码 Azure 移动服务 JWT token 时出现 JwtSecurityToken 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18273776/