对于IMAP.ACCESSUSER.ALL SCOPE ADSTS65001:用户或管理员尚未同意使用该应用程序

发布于 2025-02-05 14:56:29 字数 2965 浏览 3 评论 0原文

在我的Java Web应用程序中,我想使用Jakarta Mail访问用户的邮箱。为此,我遵循 https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-to-to-to-authenticate-antenticate-an--an-imap-pop-pop-pop-smtp -OAuth2授权代码流。

在Azure端口上,我设置了我的应用程序,并在下面添加了API权限,如

”在此处输入映像说明“

现在用户正在重定向到授权端点下方:

“ nofollow noreferrer”> https> httpps:httpps:///logoftinline。 COM/5426EE07-9B73-4A9E-8075-395AB439C6FA/OAUTH2/V2.0/授权?client_id = B6067AD9-7195-4 Back/Microsoft& wonsevy_mode = QUERY& scope = offline_access%20Https%3A%2f%2f%2fgraph.microsoft.com%2fimap.accessasuser.all%20HTTTPS%3A%2F%2fgraph.microsoft.microsoft.microsoft.microsoft.com%2fsmtp.sendements and Enterienting and Entering andering

同意REDIRECT_URI被验证代码击中。基于该验证代码,我形成了令牌端点URL并从服务器击中它,令牌端点如下:

url:

revestmt

client_id=b6067ad9-7195-430b-a35d-97b7aa7beb8f
scope=offline_access%20https%3A%2F%2Foutlook.office.com%2FIMAP.AccessAsUser.All
redirect_uri=http://localhost:8080/callback/microsoft
grant_type=authorization_code
client_secret=QUs8Q~aboLBiopTezMTKwzQjIwWsFFXjc2kCRaRs (I know I have shared the secret)
code={code received from authorize end point}

https://login.microsoftonline.com/5426ee07-9b73-4a9e-8075-395-395-395ab4395b439c6c6fa/oauth2/oauth2/oauth22/oauth22/oauth22/c.0/ 对于此帖子请求为:

{“错误”:“ Invalid_grant”,“ error_description”:“ AADSTS65001:尚未同意将应用程序与ID'B6067AD9-7195-430B-A35D-97b7aaa7beb8f命名的ID'B6067AD9-7195-430B-a连接器'发送此用户和资源的交互式授权请求。 -06-07 19:51:30z“,“ error_codes”:[65001],“时间戳”:“ 2022-06-07 19:51:30z”,“ trace_id”:“ dc008ced-e23f-4919-bd45-bd45-bd45-b7Aeae7Aeae7c68b000 “,” correlation_id”:“ 9B6EDE03-3C05-4A78-8975-036A3CB20773”,“ SUBERROR”:“ CONSENT_REQUIREID”}

在这里,我不明白为什么该错误是说明了该错误是用户不同意使用该应用程序的,在授权终点输入凭据之后,用户已接受了同意。如果我们查看上面的屏幕截图已经授予了访问目录的赠款,则更多事件。

In my java web application I want to get access to user's mailbox by using jakarta mail. For that purpose I followed https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth for OAuth2 authorization code flow.

On Azure port I setup my app and added API permissions as below

enter image description here

Now user is redirecting to below authorize endpoint:

https://login.microsoftonline.com/5426ee07-9b73-4a9e-8075-395ab439c6fa/oauth2/v2.0/authorize?client_id=b6067ad9-7195-430b-a35d-97b7aa7beb8f&response_type=code&redirect_uri=http://localhost:8080/callback/microsoft&response_mode=query&scope=offline_access%20https%3A%2F%2Fgraph.microsoft.com%2FIMAP.AccessAsUser.All%20https%3A%2F%2Fgraph.microsoft.com%2FSMTP.Send

After entering credentials and accepting the consent redirect_uri gets hit with auth code. Based on that auth code I formed token endpoint URL and hitting it from server, the token endpoint is as follow:

URL: https://login.microsoftonline.com/5426ee07-9b73-4a9e-8075-395ab439c6fa/oauth2/v2.0/token

Form Data:

client_id=b6067ad9-7195-430b-a35d-97b7aa7beb8f
scope=offline_access%20https%3A%2F%2Foutlook.office.com%2FIMAP.AccessAsUser.All
redirect_uri=http://localhost:8080/callback/microsoft
grant_type=authorization_code
client_secret=QUs8Q~aboLBiopTezMTKwzQjIwWsFFXjc2kCRaRs (I know I have shared the secret)
code={code received from authorize end point}

Response to this post request comes as:

{"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID 'b6067ad9-7195-430b-a35d-97b7aa7beb8f' named 'Email Connector'. Send an interactive authorization request for this user and resource.\r\nTrace ID: dc008ced-e23f-4919-bd45-b7ae7c68b000\r\nCorrelation ID: 9b6ede03-3c05-4a78-8975-036a3cb20773\r\nTimestamp: 2022-06-07 19:51:30Z","error_codes":[65001],"timestamp":"2022-06-07 19:51:30Z","trace_id":"dc008ced-e23f-4919-bd45-b7ae7c68b000","correlation_id":"9b6ede03-3c05-4a78-8975-036a3cb20773","suberror":"consent_required"}

Here, I don't understand why the error is saying The user or administrator has not consented to use the application, user has accepted the consent after entering credentials on authorize end point. Event more If we look at the screenshot above admin has already given grant to access the directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑶笙 2025-02-12 14:56:29

我试图在环境中重现相同的方案,并获得了与以下相同的错误:

“在此处输入映像说明”

解决错误,请检查 授权端点 您正在使用来获取代码。

  • 获取代码时避免使用 Microsoft Graph API示波器
  • 将其替换为范围您用来获取访问令牌如下:
https://login.microsoftonline.com/Your_TenantID/oauth2/v2.0/authorize?
client_id=Your_ClientID
&response_type=code
&redirect_uri=http://localhost:8080/callback/microsoft
&response_mode=query
&scope= offline_access https://outlook.office.com/IMAP.AccessAsUser.All 
&state=12345

从上面的授权端点获取 代码

在修改终点之后,我成功获得了访问令牌:

”

以验证访问token在<<< a href =“ https://jwt.io” rel =“ nofollow noreferrer”> jwt.io 并检查 aud> aud scp 索赔如下:

“

I tried to reproduce the same scenario in my environment and got the same error as below:

enter image description here

To resolve the error, please check the authorize endpoint you are using to get the code.

  • Avoid using Microsoft graph API scopes while getting the code.
  • Replace it with the scope you are using to get access token like below:
https://login.microsoftonline.com/Your_TenantID/oauth2/v2.0/authorize?
client_id=Your_ClientID
&response_type=code
&redirect_uri=http://localhost:8080/callback/microsoft
&response_mode=query
&scope= offline_access https://outlook.office.com/IMAP.AccessAsUser.All 
&state=12345

Get the code from the above authorization endpoint.

I got the access token successfully after modifying the endpoint like below:

enter image description here

To validate the access token decode it in jwt.io and check the aud and scp claims like below:

image

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文