0

I am trying to get the refereh_token, access_token using Google Auth Exchange Code, went through the documentation but it doesn't work, I am using a react-google-login for Auth and getting the code in response and i am passing the code https://accounts.google.com/o/oauth2/token but its giving error

{
"error": "invalid_grant",
"error_description": "Bad Request"
}

i have tried lots of ways

code=4%2FKxoYTS-jeq5-d6Lv7YvSz9ZrK0pJ_5lZsMExzNC1M0o&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=407408718192.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code

frontend is reactjs and backend is nodejs..

Narendra Chouhan
  • 2,291
  • 1
  • 15
  • 24

1 Answers1

0

To get the ACCESS token using referesh token you have to call a api which will give you a new access token call a POST APi https://www.googleapis.com/oauth2/v4/token

pass the body as x-www-form-urlencoded i.e

Header as Content-Type : application/x-www-form-urlencoded

Body

client_secret : 'xxxxxxxxxxxxdxxxxxSSd'<YourClientSecret>

grant_type : refresh_token'

refresh_token : '1/DDPkddk514451xxxxxxxx' <YourRefreshToken>

client_id : 'xxxxxxxxxxxxxxx' <YourClientID>

for more reference you can read this https://developers.google.com/identity/protocols/OAuth2WebServer

Narendra Chouhan
  • 2,291
  • 1
  • 15
  • 24