无法使用 decorator.http() 授权 tokeninfo oauth2 请求



要访问TokenInfo,我使用Google APIs Client Library for Python(oauth2client应用程序引擎)。我收到了一个 oauth2 访问令牌,这段代码工作正常:

@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)    

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

@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") 

我收到:

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

更新-1

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

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

更新-2 并已解决

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

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

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

更新和解决

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

最新更新