【发布时间】:2017-07-13 19:45:01
【问题描述】:
我正在尝试使用 ADAL python 包访问 MSGraph API。这是我如何获取授权令牌的代码 sn-p。
authority = "https://login.microsoftonline.com/" + tenant
RESOURCE = "https://graph.microsoft.com"
context = adal.AuthenticationContext(authority)
#Use this for Client Credentials
token = context.acquire_token_with_client_credentials(
RESOURCE,
client_id,
client_secret
)
在以这种形式提出此请求后,我得到了一个令牌:
{
"tokenType": "Bearer",
"_clientId": <clientID>,
"_authority": "https://login.microsoftonline.com/<tenant>",
"expiresIn": 3599,
"isMRRT": true,
"accessToken": <token>,
"resource": "https://graph.microsoft.com",
"expiresOn": "2017-07-13 16:38:11.591687"
}
现在,我正在使用这个令牌来发出一个 http 请求,如下所示:
request_url = 'https://graph.microsoft.com/v1.0/users'
h = {'Authorization': 'Bearer ' + token['accessToken']}
response = requests.get(url = request_url, headers = h)
我收到这样的回复:
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "f8c634c0-e23a-4f46-8e39-70ed9e35ef68",
"date": "2017-07-13T19:38:13"
}
}
}
我的问题是:为什么?我已在 Microsoft 应用注册门户中应用了必要的权限。我还设法使用Microsoft Graph Python connect sample 获得了这个请求的一个实例,所以我知道我能够访问数据。为什么我不能让这个实例工作?谢谢。
【问题讨论】:
标签: python azure-active-directory microsoft-graph-api