Azure AD令牌调用MS Graph Api以获取电子邮件消息-未经401授权

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

我已经为这个问题苦苦挣扎了2天。

我目前正在尝试构建一个Web应用程序,该应用程序可以撤消MS Graph Api以获取当前用户的电子邮件。

首先,我已经在其中注册了一个AD和一个应用程序,并按照说明设置了权限。

现在,我已经通过使用ADAL.js库获得了访问令牌。访问令牌为jwt格式,当我通过jwt.ms检查它时,似乎拥有我需要的所有权限:

"scp": "Mail.Read Mail.ReadWrite profile User.Read User.Read.All User.ReadBasic.All User.ReadWrite User.ReadWrite.All"

然后,当我尝试使用访问令牌来调用图形API时:

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

它有效,并返回了我的个人资料详细信息。

但是当我使用令牌调用时:GET“ https://graph.microsoft.com/v1.0/me/mailFolders/

它返回401未经授权的错误:

code: "OrganizationFromTenantGuidNotFound"
message: "The tenant for tenant guid <my tenant id> does not exist.

我尝试同时使用JavaScript Fetch和PostMan尝试api,返回了相同的错误。

任何人都可以帮忙,我将非常感激!

谢谢

azure-active-directory microsoft-graph azure-ad-graph-api http-status-code-401
1个回答
0
投票

您的访问令牌中缺少权限Mail.ReadBasic(or Mail.ReadBasic.All)。请参考邮件文件夹图形api的官方document(如下屏幕截图所示)enter image description here

权限Mail.ReadMail.ReadWrite包含在访问令牌中,但是您需要添加权限Mail.ReadBasic(or Mail.ReadBasic.All)。如果将“密码”用作grant_type,则需要添加权限Mail.ReadBasic。如果将“ client_credentials”用作grant_type,则应添加权限Mail.ReadBasic.All

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