JwtSecurityToken exception while decoding Azure Mobile Services JWT token(解码 Azure 移动服务 JWT 令牌时出现 JwtSecurityToken 异常)
问题描述
以下代码:
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' 部分是:
When the 'header' section of the rawToken is:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6MH0
可以解码为:
{"alg":"HS256","typ":"JWT","kid":0}
错误令牌的来源是 Azure 移动服务
.
The source of the faulting token is Azure Mobile Services
.
请注意,当'header'部分是:调用同一行代码时不会发生异常:
Please note that the exception does not occur when calling the same line of code while the 'header' section is:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjAifQ
可以解码为:
{"alg":"HS256","typ":"JWT","kid":"0"}
我怎样才能克服这个问题,并正确验证这样的令牌?
How can I overcome this problem, and properly validate such a token?
推荐答案
这是 Azure 移动服务中的一个错误,它与 JWT 规范的一致性有关.该错误已得到修复,因此移动服务生成的 JWT 现在应该在其标头的kid"字段中具有正确的字符串值.
This was a bug in the Azure Mobile Services with respect to its conformance with the JWT spec. The bug has since been fixed, so the JWTs generated by the mobile services should now have a correct string value in the "kid" field of its header.
这篇关于解码 Azure 移动服务 JWT 令牌时出现 JwtSecurityToken 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:解码 Azure 移动服务 JWT 令牌时出现 JwtSecurityToke


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04