Azure 生成令牌签名无效

问题描述 投票:0回答:1

我正在尝试使用 Microsoft Azure 生成 JWT。我成功获取了令牌,但是当我将其包含在 REST API 请求的标头中时,出现以下错误:

令牌验证失败:JWT 由于签名无效而被拒绝。其他详细信息:[[9] 无效的 JWS 签名:JsonWebSignature

然后我使用

jwt.io
来验证令牌,虽然我能够看到 JWT 中的所有声明和信息,但签名部分被标记为无效。

什么可能导致此问题?如何解决使用Azure生成的JWT时出现“无效签名”问题?

这是我使用 Postman 生成令牌的信息

代币网址

https://login.microsoftonline.com/XXXXXXX/oauth2/v2.0/token

Client_id:

CCCCC

范围:

openid profile email

grant_type
:密码为用户名和密码

azure jwt access-token
1个回答
0
投票

同意@junnas,需要使用应用程序定义的范围请求令牌。

注意:Microsoft Graph API 令牌不用于验证,

aud: httos://graph.microsoft.com
,因为它不用于应用程序验证。

使用 ROPC 流程,我尝试使用用户名和密码生成访问令牌。

GET https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
scope:https://graph.microsoft.com/.default
grant_type:password
username: <username>
password: <password>

enter image description here

当我在

https://jwt.io
上使用 scope: https:/graph.microsoft.com 解码访问令牌时,我收到了相同的无效签名错误消息。

enter image description here enter image description here

要解决该错误,您必须避免使用 Microsoft Graph API 验证访问令牌。您必须使用您自己的应用程序或您自己的自定义 API 来验证访问令牌。

添加了应用程序 ID URI,并公开了如下 API:

enter image description here

您可以在API权限刀片中找到上述API,仅包含应用程序名称:

enter image description here

现已添加公开 API 权限:

enter image description here

已获得管理员同意添加的权限:

enter image description here

现在我在生成访问令牌时更改了范围

 scope : api://<application-id>/Custom.Read

enter image description here

现在,当我使用 scope : api://<application-id>/Custom.Read

http://jwt.io
解码生成的访问令牌时,现在我可以验证访问令牌了。

enter image description here enter image description here

参考:

吉尔伯特的SO主题

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.