我正在尝试从我们组织的 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/