【发布时间】:2017-01-24 22:00:30
【问题描述】:
我们在 Azure 上有一个应用程序,经过大量工作和挫折,到目前为止我们已经能够阅读用户的电子邮件。
出于测试目的,我为应用程序提供了几乎完全访问权限(见下图)),包括但不限于代表用户发送电子邮件、阅读用户电子邮件等。我知道我们不必给予除非需要,否则应用程序进行此类访问,但这只是为了发送电子邮件。
我有这个 curl 代码用于发送电子邮件的测试目的
curl -i https://graph.microsoft.com/v1.0/me/sendmail -H 'Content-Type: application/json' -X POST -d '{"Message":{"Subject": hi", "Body": {"ContentType": "Text", "Content": "body"},"ToRecipients":[{"EmailAddress": {"Address": "alerts-noreply@mail.windowsazure.com"}}]},"SaveToSentItems": "true"}' -H 'Authorization: Bearer eyJ......TOKEN.....YlhaHbAFQ'
它给了我这个错误
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again.",
"innerError": {
"request-id": "4895f98f-c5a4-4083-867b-f6c7b4634b7f",
"date": "2017-01-24T21:48:47"
}
}
}
如果应用程序具有这样的完全访问权限,为什么应用程序会被拒绝?
令牌被以下代码获取:
https://login.microsoftonline.com/f0263....0be3/oauth2/authorize?client_id=8a676..e4b6&redirect_uri=http://www.wrabc.com:8090/&response_type=code.
感谢您的帮助。
【问题讨论】:
-
为了缩小这个问题的范围,我建议你解析this site的token表单,检查
scp声明中是否有Mail.Send。 -
@FeiXue-MSFT 我看到下面的“scp”:“Mail.ReadWrite Mail.ReadWrite.Shared MailboxSettings.ReadWrite User.Read”,没有 Mail.Send。
-
我尝试了 POST outlook.office.com/api/v1.0/me/folders/inbox/messages(to 草稿消息),它成功了。我看到 Mail.Send 范围存在问题。我去了 Azure AD 中的权限,我可以看到所有内容都被选中,包括“以用户身份发送邮件”。在我这样做之后,检索了一个新令牌,但它仍然没有 mail.send scp。不知道我必须做什么。
标签: azure microsoft-graph-api azure-active-directory azure-ad-graph-api