MS Graph API:无效的身份验证令牌 [英] MS Graph API: invalid authentication token

查看:751
本文介绍了MS Graph API:无效的身份验证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Microsoft Graph API查询Outlook/O365邮箱中的消息.我在Azure门户中注册了我的应用,并收到了用于查询的必要信息API.该应用程序具有Mail.Read权限. (我没有访问Azure门户的权限,并被告知它是用这种方式设置的.)但是,当我从OAuth终结点获取令牌时,它在任何后续调用中均不起作用.我现在正在使用Python的请求模块进行测试.

I'm trying to use the Microsoft Graph API to query an Outlook/O365 mailbox for messages. I registered my app in the Azure portal and received the necessary information to query the API. The app has the Mail.Read permission. (I don't have access to the Azure portal, I was told it was set up this way.) When I get my token from the OAuth endpoint, however, it doesn't work in any subsequent calls. I'm using Python's requests module for testing right now.

为什么此呼叫失败?似乎我传递了所有正确的信息,但显然缺少某些内容.

Why is this call failing? It seems like I'm passing all of the correct information but I'm clearly missing something.

我通过在以下位置执行POST来获得令牌:

I'm getting the token by performing a POST on:

https://login.microsoftonline.com/my.domain/oauth2/token

我传递了必要的参数:

data = {'grant_type': 'client_credentials', 'client_id': CLIENTID, 'client_secret': SECRET, 'resource': APPURI}

我得到这样的答复:

{
    'resource': 'APPURI',
    'expires_in': '3599',
    'ext_expires_in': '3600',
    'access_token': 'TOKENHERE',
    'expires_on': '1466179206',
    'not_before': '1466175306',
    'token_type': 'Bearer'
}

但是,我尝试使用该令牌,并且它对我所说的任何东西都无效.我将其作为标头传递:

I try to use that token, however, and it doesn't work for anything I call. I'm passing it as a header:

h = {'Authorization': 'Bearer ' + TOKEN}

我正在呼叫此URL:

url = 'https://graph.microsoft.com/v1.0/users/my.email.address@example.com/messages'

具体地说,我用这个:

r = requests.get(url, headers=h)

响应为401:

{
    'error': {
        'innerError': {
            'date': '2016-06-17T15:06:30',
            'request-id': '[I assume this should be removed for privacy]'
         },
         'code': 'InvalidAuthenticationToken',
         'message': 'Access token validation failure.'
     }
}

推荐答案

在您的登录请求中,资源参数应为 https: //graph.microsoft.com

in your login request, the resource parameter should be https://graph.microsoft.com

这篇关于MS Graph API:无效的身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆