尝试使用个人帐户获取authorization_code,但收到AADSTS9002313错误

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

我在 Azure 中创建了一个身份验证应用程序以允许所有用户访问。但是,我只能使用我组织内的帐户访问它;组织外的账户(xbox live账户或其他)无法获取验证码并遇到错误

{"error":"invalid_grant","error_description":"AADSTS9002313: Invalid request. Request is malformed or invalid. Trace ID: 7473f2b4-1e1b-4428-8e44-dbb5a6aab900 Correlation ID: 4930db75-6422-41d2-84f4-7ed4655881e9 Timestamp: 2024-03-26 09:10:29Z","error_codes":[9002313],"timestamp":"2024-03-26 09:10:29Z","trace_id":"7473f2b4-1e1b-4428-8e44-dbb5a6aab900","correlation_id":"4930db75-6422-41d2-84f4-7ed4655881e9","error_uri":"https://login.microsoftonline.com/error?code=9002313"}"

当我得到重定向网址时http://localhost:8080/api/admin/office365_calendar/refresh_token?code=M.C549_BAY.2.U.49655a0d-92d0-9af4-a8ca-168d922a125e&state=71074f34-96f0-4ad3 -84b4-69c35c9b208a 哪个代码显然很奇怪......

这是我的端点:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?

我的设置应该是正确的,如下图所示:

有人可以告诉我如何解决吗?

java azure azure-active-directory
1个回答
0
投票

如果您使用个人 Microsoft 帐户(Outlook、Gmail) 登录,您的

code
值将以 M.C 开头,这是默认行为。

我注册了一份多租户申请并授予了

API permissions
,如下:

enter image description here

就我而言,我在应用程序注册中使用 https://jwt.ms 作为 重定向 URI

enter image description here

当我运行下面的授权 URL 并使用 个人 Microsoft 帐户登录时,我也得到了

code
值以 M.C 开头:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize? 
client_id=appID
&redirect_uri=https://jwt.ms
&response_type=code
&prompt=select_account    
&scope=openid offline_access Calendars.ReadWrite User.Read
&state=12345

enter image description here

现在,我使用这个

code
通过Postman使用以下参数生成访问令牌,并得到像这样的响应

POST https://login.microsoftonline.com/common/oauth2/v2.0/token
grant_type: authorization_code
client_id: appId 
client_secret: secret 
scope: https://graph.microsoft.com/.default
code: paste_code_from_above
redirect_uri: https://jwt.ms

回复:

enter image description here

当我使用此令牌来获取用户的日历事件时,我成功地得到了response,如下所示:

GET https://graph.microsoft.com/v1.0/me/events

回复:

enter image description here

参考: php - 如何在 Microsoft graph API 中使用用户的访问令牌或基于租户 ID 的访问令牌? - 堆栈溢出

© www.soinside.com 2019 - 2024. All rights reserved.