Not able to fetch Google OAuth 2.0 access token

橙三吉。 提交于 2019-12-02 06:31:20

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:

  1. don't use the -F flag as it will produce a multipart-formdata header but you need www-form-urlencoded as produced with -d
  2. don't use the -k flag towards Google as that makes things insecure; Google presents a valid SSL certificate that you should check
  3. 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.com' \
    -d 'client_secret=xxx' \
    -d 'redirect_uri=https%3A%2F%2Fwww%2Eexample%2Ecom%2Foauth2callback' \
    -d 'grant_type=authorization_code' \
    https://accounts.google.com/o/oauth2/token
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!