Microsoft Graph API无法使用mail.read

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

在我的应用程序中,我通过生成访问令牌

GET https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/authorize?client_id=<CLIENT_ID>&response_type=code&response_mode=query&scope=user.read+mail.send+mail.readwrite&redirect_uri=https%3A%2F%2Fgraphresponse%2F&prompt=consent

使用代码

POST https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token

application/x-www-form-urlencodedgrant_type=authorization_code&redirect_uri=https%3A%2F%2Fgraphresponse%2F&client_id=<CLIENT_ID>&scope=user.read+mail.send+mail.readwrite&client_secret=<CLIENT_SECRET>&code=<CODE>

到目前为止,我收到了这样的持有人令牌(为便于阅读而格式化):

{"token_type":"Bearer",
 "scope": 
      "Mail.Read Mail.Read.All Mail.Read.Shared 
       Mail.ReadBasic Mail.ReadWrite Mail.ReadWrite.Shared 
       Mail.Send openid User.Read profile email",
 "expires_in":3600,
 "ext_expires_in":3600,
 "access_token":"<TOKEN>"
}

我可以使用以下端点

GET http://graph.microsoft.com/v1.0/me 
POST http://graph.microsoft.com/v1.0/me/sendMail 
POST http://graph.microsoft.com/v1.0/me/messages

但是我收到以下错误

GET http://graph.microsoft.com/v1.0/me/messages

{
  "error": {
    "code": "ErrorAccessDenied",
    "message": "Access is denied. Check credentials and try again.",
    "innerError": {
      "request-id": "xxxxxxx",
      "date": "2019-03-12T13:38:47"
    }
  }
}

我是否错过了显式读取当前用户收件箱所需的任何配置,或者是否需要任何管理配置?

oauth-2.0 azure-active-directory microsoft-graph azure-ad-graph-api microsoft-graph-mail
1个回答
0
投票

当您尝试使用authorization code flow时,您需要按照以下步骤操作

步骤访问

https://graph.microsoft.com数据。

注意:

  1. 确保您已注册Office 365用户帐户
  2. 所有必需的permission grant

作为document explain首先你需要令牌请求代码

response_type =代码

要做到这一点,有两种方法。

来自邮递员请求和来自浏览器的所需凭据

在这里,我将展示邮递员的解决方法,你也可以尝试粘贴在浏览器上。

邮差代码访问示例

这里确保您在门户网站中按预期配置此URL,请参阅以下屏幕截图:

enter image description here

要获得v2.0令牌请​​求访问代码集请求端点到:

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

内容类型为:application / x-www-url-form-urlencoded

请参见下面的屏幕截图:

enter image description here

现在单击“授权”选项卡,选择“键入OAuth 2.0”,然后单击“获取新访问权限”

令牌。请参见下面的屏幕截图:

enter image description here

你会提示邮递员弹出如下:

enter image description here

在此输入您需要的信息,然后单击请求令牌

在邮递员控制台主体细分中,您将获得令牌请求的访问代码。请参见下面的屏幕截图:

enter image description here

复制代码以供下次使用。

现在在帖子man上为标记请求添加一个新标签,如下所示:

enter image description here

作为回应,您将获得如下访问令牌:

enter image description here

现在将此令牌请求发送到您的预期端点,例如http://graph.microsoft.com/v1.0/me

请参见下面的屏幕截图:

enter image description here

作为响应,您将按预期获得端点数据

请参见下面的屏幕截图:

enter image description here

如果您有任何疑问,请告诉我,谢谢。

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