How to get Google OAuth 2.0 Access token directly using curl? (without using Google Libraries)

前端 未结 2 1635
半阙折子戏
半阙折子戏 2021-02-04 02:21

I\'m trying to follow this tutorial to authenticate with Google using their OAuth 2.0 API. However, I would like to make straight curl calls rather than use their l

相关标签:
2条回答
  • 2021-02-04 03:01

    a) the data you provide should be form-encoded instead of presented as a JSON object and b) you should also provide an authorization code value in the "code" parameter. E.g.:

    curl -d "client_id=MY_CLIENT_ID&\
      client_secret=MY_SECRET_KEY&\
      redirect_uri=http://localhost/etc&\
      grant_type=authorization_code&\
      code=CODE" https://oauth2.googleapis.com/token
    
    0 讨论(0)
  • 2021-02-04 03:06

    While not directly using CURL, you can also get and test OAuth tokens using the Google OAuth Playground: https://developers.google.com/oauthplayground/

    0 讨论(0)
提交回复
热议问题