【发布时间】:2019-06-07 02:21:30
【问题描述】:
在this主题中,作者解释了如何根据用户登录名和密码获取访问令牌,跳过授权对话框。
我可以点击端点并获取访问令牌,然后刷新令牌:
GET https://login.microsoftonline.com/348a...6e4/oauth2/token?grant_type=password&\
client_id=6d5f...64f&client_secret=g...f2&username=user@Domain.com&\
password=P@ssW0RD&resource=https://graph.microsoft.com/&\
scope=user.read%20calendars.read%20MailboxSettings.Read%20Mail.read%20Mail.Send
//RESPONSE
{
"token_type": "Bearer",
"scope": "User.Read",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1559602338",
"not_before": "1559598438",
"resource": "https://graph.microsoft.com/",
"access_token": "eyJ0eXAiOiJKV...KJmNhyz5bvhzCWiFA",
"refresh_token": "AQABAAA...VkgAA",
"id_token": "eyJ0...xLjAifQ."
}
但是当我尝试获取用户的电子邮件时,我收到了一个错误:
GET https://graph.microsoft.com/v1.0/me/messages?\
$select=sender,subject,ReceivedDateTime&\
$filter=ReceivedDateTime%20ge%202019-05-01&$top=20
RESPONSE
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again.",
"innerError": {
"request-id": "e35f...94",
"date": "2019-06-03T21:39:40"
}
}
}
这种身份验证方法对 Microsoft Graph API 仍然有效吗?如果没有,是否有其他方法可以仅使用登录名和密码获得用户授权,无需任何用户交互,只需获取他的登录名和密码?
【问题讨论】: