HTTP 302 when trying to obtain access token

3,138 views
Skip to first unread message

Henning Eggers

unread,
May 9, 2012, 6:19:31 PM5/9/12
to oauth...@googlegroups.com
Hi!

I am following the steps outlined in https://developers.google.com/accounts/docs/OAuth2WebServer to be able to make API calls from my web application. I am getting a code back through the redirect uri but after that I hit a wall trying to obtain an access token with that code.

The documentation says to do a POST request to https://accounts.googleapis.com/o/oauth2/token and post the code, client_id, client_secret and grant_type in the body. I am supposed to get a JSON response but I keep getting a 302 response which redirects me to www.google.com. I tried with both python urllib2 and curl, same response. Here is the curl output:

> POST /o/oauth2/token HTTP/1.1
> User-Agent: curl/7.21.6 (i686-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
> Accept: */*
> Content-Length: 236
> Content-Type: application/x-www-form-urlencoded
< HTTP/1.1 302 Found
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Content-Length: 218
< Date: Wed, 09 May 2012 21:57:08 GMT
< Server: GFE/2.0
< Connection: close

What am I missing here? Any hint is appreciated.

Henning

Marius Scurtescu

unread,
May 9, 2012, 7:54:33 PM5/9/12
to oauth...@googlegroups.com
Hi Henning,

The host name is wrong, see bellow...

On Wed, May 9, 2012 at 3:19 PM, Henning Eggers <hen...@keeeb.com> wrote:
> Hi!
>
> I am following the steps outlined
> in https://developers.google.com/accounts/docs/OAuth2WebServer to be able to
> make API calls from my web application. I am getting a code back through the
> redirect uri but after that I hit a wall trying to obtain an access token
> with that code.
>
> The documentation says to do a POST request
> to https://accounts.googleapis.com/o/oauth2/token and post the code,

the post request should go to host:
accounts.google.com

(as opposed to accounts.googleapis.com)


Can you please point me to the documentation that says this, so we can fix it?


Thanks,
Marius

Henning Eggers

unread,
May 10, 2012, 4:10:40 AM5/10/12
to oauth...@googlegroups.com
Hello Marius!


On Thursday, May 10, 2012 1:54:33 AM UTC+2, Marius Scurtescu wrote:

the post request should go to host:
accounts.google.com

(as opposed to accounts.googleapis.com)

Thank you very much, that did it!

 

Can you please point me to the documentation that says this, so we can fix it?



It does not, it was my error. Sorry. Somehow I must have gotten confused and never double-checked the host name. What would help in the documentation, though, is to list this endpoint explicitly, like the others.

e.g.:

EndpointDescription
https://accounts.google.com/o/oauth2/tokenThis endpoint receives a POST request to exchange an authorization code for an access token.


Cheers,
Henning

Reply all
Reply to author
Forward
0 new messages