guruahn / vue-google-oauth2

🔌 Handling Google sign-in and sign-out for Vue.js applications
MIT License
184 stars 55 forks source link

Invalid JSON payload received. Unexpected token.\nclient_id=xxxx\n^ error when use authCode to exchange access and refresh token #52

Closed t-tien closed 3 years ago

t-tien commented 3 years ago

Describe the bug I'm used vue-google-oauth2 to get authCode from google, then I want to use it to exchange access and refresh token by below:

curl -d "client_id=0123456789012-xxxxxxxxxxx&\
  client_secret=CLIENT_SECRET&\
  redirect_uri=postmessage&\
  grant_type=authorization_code&\
  code=AUTH_CODE" -H "Content-Type: application/json" -H "Content-Type: application/x-www-form-urlencoded" --header 'Accept: application/json' https://accounts.google.com/o/oauth2/token

but I get an 400 error:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unexpected token.\nclient_id=012345678\n^",
    "status": "INVALID_ARGUMENT"
  }
}

What I went wrong? Thanks for your support

To Reproduce

Replace client_id, client_secret, auth_code and run above Curl command

Expected behavior

Google OAuth response access token and refresh token

t-tien commented 3 years ago

I figure out that delete back slash can solve the problem curl -d "client_id=[CLIENT_ID]&client_secret=[CLIENT_SECRET]&redirect_uri=postmessage&grant_type=authorization_code&code=[AUTH_CODE]" https://oauth2.googleapis.com/token