无法使用decorator.http()授权tokeninfo oauth2请求 [英] Failed to authorize tokeninfo oauth2 request using decorator.http()

查看:139
本文介绍了无法使用decorator.http()授权tokeninfo oauth2请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要访问TokenInfo,我使用Python的Google API客户端库(oauth2client应用程序引擎)。
我收到了一个oauth2访问令牌,这段代码工作的很好:

  @ decorator.oauth_aware 
def get(self):

....
....
如果decorator.has_credentials():
body = urllib.urlencode({'access_token' :decorator.credentials.access_token})
http = httplib2.Http()
resp,content = http.request(https://www.googleapis.com/oauth2/v1/tokeninfo,method, =POST,body = body)

但是当我使用装饰器创建一个授权的http实例:

  @ decorator.oauth_aware 
def get(self):

... 。
....
如果decorator.has_credentials():
http = decorator.http()
resp,content = http.request(https:// www。我收到: > / p>

 'status':'400 
{
error:invalid_token,
error_description:需要access_token或id_token
}
pre>

UPDATE-1



我研究了oauth2client\client.py: decorator.http()不仅授权请求,而且刷新access_token,如果已过期。



我非常欢迎有关如何解决此问题的想法?谢谢你的帮助。

更新-2和已解决



TokeInfo API不需要任何授权。请求本身必须包含access_token。

解决方案

我研究了oauth2client\client.py:decorator.http()不仅授权请求,但如果它已过期,也会刷新access_token。



我非常欢迎有关如何解决此问题的想法?感谢您的帮助。

更新并解决了

TokeInfo API不需要任何授权。请求本身必须包含access_token。授权标头将被忽略。


To access TokenInfo I use the Google APIs Client Library for Python (oauth2client app engine). I have received an oauth2 access token and this code works fine:

@decorator.oauth_aware        
def get(self):

    ....
    ....
    if decorator.has_credentials() :
        body = urllib.urlencode({'access_token': decorator.credentials.access_token})
        http = httplib2.Http()
        resp, content = http.request("https://www.googleapis.com/oauth2/v1/tokeninfo",method="POST", body=body)    

But when I use the decorator to create an authorized http instance:

@decorator.oauth_aware        
def get(self):

    ....
    ....
    if decorator.has_credentials() :
        http = decorator.http()                              
        resp, content = http.request("https://www.googleapis.com/oauth2/v1/tokeninfo",method="POST") 

I receive:

'status' : '400'
{
 "error": "invalid_token",
 "error_description": "either access_token or id_token required"
}

UPDATE-1

I studied oauth2client\client.py : decorator.http() not only authorizes the request, but also refreshes the access_token if it has been expired.

I very welcome ideas on how to solve this? Thanks for your help.

UPDATE-2 AND SOLVED

The TokeInfo API does not need any Authorization. The request itself has to contain the access_token. The Authorization header is ignored.

解决方案

I studied oauth2client\client.py : decorator.http() not only authorizes the request, but also refreshes the access_token if it has been expired.

I very welcome ideas on how to solve this? Thanks for your help.

UPDATE AND SOLVED

The TokeInfo API does not need any Authorization. The request itself has to contain the access_token. The Authorization header is ignored.

这篇关于无法使用decorator.http()授权tokeninfo oauth2请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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