jscherman
jscherman

Reputation: 6189

missing grant_type parameter in google oauth api v2?

I am doing this request:

POST request to
https://accounts.google.com/o/oauth2/token?
client_secret=xxxxx-x8U-tDOJbCPN3&
grant_type=authorization_code&
redirect_uri=[url]
client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&
code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI

So, as doc says, i make that request with these headers:

"Accept-Encoding": "gzip"
"Content-Type": "application/x-www-form-urlencoded"

But when i do it i am getting a 400:

{"error":"invalid_request","error_description":"Required parameter is missing: grant_type"}

Upvotes: 3

Views: 6674

Answers (2)

jscherman
jscherman

Reputation: 6189

I have already solved this. The problem was that i was sending params in query string, and the correct way was sending them as x-www-form-urlencoded. So the correct request had to be like this:

POST /o/oauth2/token? HTTP/1.1
Host: accounts.google.com
Cache-Control: no-cache
Postman-Token: b38df5b3-b64f-338a-1374-220647ee05a0
Content-Type: application/x-www-form-urlencoded

client_secret=xxxxx-x8U-tDOJbCPN3%26&grant_type=authorization_code&redirect_uri=myredirecturi&client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI

Hope this helps

Upvotes: 10

Remi D
Remi D

Reputation: 643

had a similar problem, but in my case it was postman leaving a stupid Content-Type:application/json in the header!

Hope this might avoid my struggling for someone having the same issue!

Upvotes: 0

Related Questions