如何使用 Google API 在 OAuth 2.0 中传递“授权"标头值 [英] How to pass 'Authorization' header value in OAuth 2.0 with Google APIs

查看:61
本文介绍了如何使用 Google API 在 OAuth 2.0 中传递“授权"标头值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 OAuth 1.0 和 2.0 访问 Google 的 API,在这两种情况下,我都需要在标头中的 Authorization 字段中填充值OAuth",然后是访问令牌.我尝试了以下方法,但 Google 向我抛出了一个错误,指出 Authorization 标头值存在问题.我正在使用 Python-Tornado

I am trying to access Google's APIs with OAuth 1.0 and 2.0 in both cases I need to fill Authorization field in the headers with value 'OAuth' followed by access token. I tried following method, but Google throws me an error saying there is problem in Authorization header values. I am using Python-Tornado

additional_headers = {
        "Authorization": "OAuth "+GoogleOAuth2Mixin.access_token,
        "Accept-Encoding": None
    }
    h = httputil.HTTPHeaders()
    h.parse_line("Authorization: OAuth "+GoogleOAuth2Mixin.access_token)
    request = httpclient.HTTPRequest(self._USER_INFO_URL+"?access_token="+GoogleOAuth2Mixin.access_token, method="GET", headers=h)
    self.httpclient_instance.fetch(
        request,
        self.async_callback(callback)
    )

我尝试使用这两种方法,通过传递标头h"和additional_headers",但它不起作用.什么是准确的方法?

I tried using both methods, by passing header 'h' and 'additional_headers', but it doesn't work. What is an accurate method?

推荐答案

我遇到了同样的问题.如果包含 'Bearer' 作为前缀,它就可以工作.

I had same problem. It works if 'Bearer ' is included as prefix.

Authorization: Bearer 0b79bab50daca910b000d4f1a2b675d604257e42

这篇关于如何使用 Google API 在 OAuth 2.0 中传递“授权"标头值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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