解码 Azure 移动服务 JWT 令牌时出现 JwtSecurityToke

JwtSecurityToken exception while decoding Azure Mobile Services JWT token(解码 Azure 移动服务 JWT 令牌时出现 JwtSecurityToken 异常)
本文介绍了解码 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 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!



本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)