Invalid_Grant on attempt to get Access_token using CODE (Google Oauth / Oauth2)

Hey guys!

So, I’m trying to get the Google acess_token using the ‘code’ I get once the user logs in using Google Oauth.

It works just fine using Weweb Rest API or Postman (as you will see on the picture), but it doesn’t work on N8N, even using the exact same values.

I do know the code can only be used once, so I generate one every test, and still shoots this ‘invalid_grant’ value.

The grant_type I’m using is ‘authorization_code’.

It doesn’t work using JSON, nor RAW or URL Encoded content-tpe, so, not a clue what’s the problem.



Does someone has any idea?

Hi zannotoal.

Hope you are well!

Add the HTTP header

Key: Content-Type
Value: application/x-www-form-urlencoded
This ensures that the data is sent in the correct URL Encoding format.

Click Send Headers and enter

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

Make sure that the {{ $json.redirect_uri }} variable you are using matches the redirect_uri you initially set in the authentication flow.

Expected Configuration (Summary)
Main Fields:
code: {{ $json.code }}
client_id: {{ $json.client_id }}
client_secret: {{ $json.client_secret }}
grant_type: authorization_code
redirect_uri: {{ $json.redirect_uri }} (or fixed)
Headers:
Key: Content-Type
Value: application/x-www-form-urlencoded

I hope I helped you in some way

1 Like

Hey Rubens!

Thank you very much for the reply.

You are amazing, I’ve been having trouble with this thing for weeks, and it worked.

I put the headers and copy/paste the redirect_uri again just to make sure and it worked.

Thank you very much.

1 Like

Thank you for your kind words, I’m glad I could help.

Could you please mark my previous post as the solution (blue box with check mark) so that this ongoing discussion doesn’t distract others who want to find the answer to the original question? Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.