无法获取Google OAuth 2.0访问令牌

编程入门 行业动态 更新时间:2024-10-24 08:26:28
本文介绍了无法获取Google OAuth 2.0访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图通过传递下面屏幕截图中显示的参数,使用REST API获取访问令牌,但我面临的错误必需的参数缺少:grant_type 。我在Chrome浏览器中尝试使用cURL和高级Rest API。我使用cURL和高级REST API发送这些参数:

I have tried to get an access token using the REST API by passing the parameters which are shown in screenshots below, but I face the error Required parameter is missing: grant_type. I have tried with cURL and the Advanced Rest API in a Chrome browser. I am sending these parameters using cURL and the Advanced REST API:

client_secret;xxx refresh_token; redirect_uri;https%3A%2F%2Fwww%2Eexample%2Ecom%2Foauth2callback scope;www.googleapis/auth/drive client_id;xxxxxxxx.apps.googleusercontent access_token;

cURL语法:

D:\>curl -k --header Content-Type=application/x-www-form-urlencoded -i -X POST "accounts.google/o/oauth2/token" -F 'code=4%2FdpbtMVUpzNFAfGHlxrNvfMlvHrPWk_m8y2I-thDdsLk.wvBSFgWEqW0Zcp7tdiljKKZFG-jOlgI' -F 'client_id=xxxxxxxx.apps.googleusercontent' -F 'client_secret=xxx' -F 'redirect_uri=https%3A%2F%2Fwww%2Eexample%2Ecom%2Foauth2callback' -F 'grant_type=authorization_code'

如何解决此问题? / p>

How to resolve this issue?

推荐答案

显然,您要调用令牌端点来交换代码 access_token 作为授权代码授权的一部分。有几件事:

Apparently you're calling the token endpoint to exchange a code for an access_token as part of an Authorization Code grant. A few things:

  • 不要使用 -F 产生 multipart-formdata 头,但您需要 www-form-urlencoded d
  • 不要向Google使用 -k 标志, Google提供您应该检查的有效SSL证书
  • 将 Content-Type 参数置于引号中
  • don't use the -F flag as it will produce a multipart-formdata header but you need www-form-urlencoded as produced with -d
  • don't use the -k flag towards Google as that makes things insecure; Google presents a valid SSL certificate that you should check
  • put the Content-Type parameter in quotes
  • 添加一些额外的语法优化后,您应该能够使用:

    after adding some additional syntax optimization you should be able to use:

    curl -v -i \ -d "code=4%2FdpbtMVUpzNFAfGHlxrNvfMlvHrPWk_m8y2I-thDdsLk.wvBSFgWEqW0Zcp7tdiljKKZFG-jOlgI" \ -d 'client_id=xxxxxxxx.apps.googleusercontent' \ -d 'client_secret=xxx' \ -d 'redirect_uri=https%3A%2F%2Fwww%2Eexample%2Ecom%2Foauth2callback' \ -d 'grant_type=authorization_code' \ accounts.google/o/oauth2/token

    更多推荐

    无法获取Google OAuth 2.0访问令牌

    本文发布于:2023-11-14 09:14:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1586814.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:令牌   Google   OAuth

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!