c# - 解码 Azure 移动服务 JWT token 时出现 JwtSecurityToken 异常

标签 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. 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/

相关文章:

c# - 如何在WPF中的静态文本段落中放置可编辑文本

c# - Azure 中的 PRM_ServerError,在模拟器中正确运行

java - 在 azure 服务器中缓慢网络上传视频文件时抛出超时异常

python - 如何使用 pydocumentdb 在 Cosmos DB 中创建分区集合?

android - 如何使用 API 代码从 Azure 移动服务在我的数组列表中存储多条记录?

javascript - MobileServiceClient.getPush() 方法在 Azure 移动服务中无效到 Android、JS 后端教程

c# - 具有自定义延迟加载对象的自动映射器

c# - 这是使用 LINQ to SQL 时的虚假警告吗?

c# - ASP.NET 身份承载 token 。是否执着?

azure - 开发者租户的图形 API token