azure-active-directory - Microsoft Graph 仅返回具有密码授予的 "User.Read"范围

标签 azure-active-directory microsoft-graph-api

我正在尝试从我们组织的 365 个销售人员电子邮件中获取电子邮件。

我正在使用 grant_type=password 并提供 scope='Mail.Read',但是,无论我在范围参数上添加什么,API 都只返回 用户.读取

我是这样打电话的:

https://login.microsoftonline.com/{mytenantId}/oauth2/token

传递以下参数:

client_id = myAppId,
client_secret = myAppPassword,
resource = 'https://graph.microsoft.com/',
username = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="295f4c474d4c4d465b694c44484045074a4644074b5b" rel="noreferrer noopener nofollow">[email protected]</a>,
password = passwordDoVendedor,
scope = 'user.read,mail.read,mail.send',
grant_type = 'password',
prompt = 'admin_consent'

无论我在范围参数上添加什么,它都只返回User.Read:

{#662
  +"token_type": "Bearer"
  +"scope": "User.Read"
  +"expires_in": "3599"
  +"ext_expires_in": "3599"
  +"expires_on": "1559623624"
  +"not_before": "1559619724"
  +"resource": "https://graph.microsoft.com/"
  +"access_token": "...token..."
  +"refresh_token": "...token..."
}

最佳答案

您无法使用 v1 端点指定范围,仅 v2 端点支持它(请参阅文档中的 Scopes, not Resources)。

为了添加 Mail.Read,您需要将其添加到 Azure 门户中的应用程序注册中。

如果我没有指出使用密码授予几乎总是是一个坏主意,那我也算是失职了。从根本上来说,它的安全性低于其他所有 OAuth 授权。

关于azure-active-directory - Microsoft Graph 仅返回具有密码授予的 "User.Read"范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56437285/

相关文章:

microsoft-graph-api - 在 MSGraph 中过滤用户

azure - 无法在 Azure AD 的 access_token 中获取电子邮件声明

authentication - 使用仅限云的 Azure Active Directory 的 SQL Azure 集成身份验证失败

microsoft-graph-api - 按正文内容过滤事件对象

azure - Microsoft Graph API 是否可以与 Office 365 家庭订阅一起使用?

java - 403 :forbidden when reading mails from server side application using Microsoft Graph

authentication - 无需注册应用程序即可通过 REST 进行 Office 365 身份验证

用于创建并登录 B2C 租户的 Azure 服务主体

asp.net - 在从本地 AD 同步的 Azure AD 上进行验证的 Multi-Tenancy 登录表单

azure - [Azure AD] : Reset Password button Disabled