400 Bad Request Error - Trying to Authenticate from Installed App

5,021 views
Skip to first unread message

mtep...@gmail.com

unread,
Feb 20, 2013, 11:43:24 PM2/20/13
to oauth...@googlegroups.com
I am trying to access Google Drive from an installed app that I am developing.

This is the HTTP request that I sent

Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded; Charset=UTF-8
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Content-Length: 239

code=4/KgR6BYpBxMZy0XMxB0lBJNrpm4PE.0gc2lQa60qwRaDn_6y0ZQNgCIn-jeQI
client_secret={ZKvGB-1llx0ML6bK1paoN3nW}&
redirect_uri=urn:ietf:wg:oauth:2.0:oob


I got a 400 Bad Request Error.

Breno de Medeiros

unread,
Feb 20, 2013, 11:50:21 PM2/20/13
to oauth...@googlegroups.com
As for the reason you're getting bad request: the client_secret appears enclosed in '{' braces. Moreover, the request doesn't appear to be properly url-encoded (e.g., the '{' are not being %-escaped). This is probably causing our server to fail to parse the request, and thus is not able to generate a more useful error message than 'bad request'.


--
You received this message because you are subscribed to the Google Groups "Developer Forum for Google API Access using OAuth2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oauth2-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--Breno

M T

unread,
Feb 21, 2013, 8:10:48 PM2/21/13
to oauth...@googlegroups.com
Thank you for helping me out.

I enclosed the client secret in braces because the documentation seemed to suggest that that is the correct way to do it.  (see the part that says what the actual request should look like.

I tried url encoding and html encoding the request and I got the same error


Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded; Charset=UTF-8
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Content-Length: 252

code=4/KgR6BYpBxMZy0XMxB0lBJNrpm4PE.0gc2lQa60qwRaDn_6y0ZQNgCIn-jeQI<br>
client_secret=ZKvGB-1llx0ML6bK1paoN3nW<br>
redirect_uri=urn:ietf:wg:oauth:2.0:oob<br>


Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded; Charset=UTF-8
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Content-Length: 259

code=4/KgR6BYpBxMZy0XMxB0lBJNrpm4PE.0gc2lQa60qwRaDn_6y0ZQNgCIn-jeQI<br>
client_secret={ZKvGB-1llx0ML6bK1paoN3nW}&amp;<br>
redirect_uri=urn:ietf:wg:oauth:2.0:oob<br>


I also tried both methods with and without braces.

Can you please send me a sample of what the request should look like?

Than you very much.

Breno de Medeiros

unread,
Feb 21, 2013, 8:12:30 PM2/21/13
to oauth...@googlegroups.com
<br> is not a proper line break. I suggest you try the request using a standard tool like curl, and see how it goes.

Vladimir Kolovski

unread,
Feb 21, 2013, 8:13:10 PM2/21/13
to oauth...@googlegroups.com
Your grant_type is wrong, shouldn't it be "authorization_code"?

Vlad


On Thu, Feb 21, 2013 at 5:10 PM, M T <mtep...@gmail.com> wrote:

M T

unread,
Feb 21, 2013, 8:40:28 PM2/21/13
to oauth2-dev
Vladimir, you are right, I changed the grant_type.

Breno, I am using fiddler.  The one with the <br> was one among many attempts.

At this point, I am thoroughly confused.

Below is my latest request and I am at a total loss as to why it's not working.


Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded; Charset=UTF-8
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Content-Length: 231

code=4/KgR6BYpBxMZy0XMxB0lBJNrpm4PE.0gc2lQa60qwRaDn_6y0ZQNgCIn-jeQI&
client_secret={ZKvGB-1llx0ML6bK1paoN3nW}&
redirect_uri=urn:ietf:wg:oauth:2.0:oob&
grant_type=authorization_code

Vladimir Kolovski

unread,
Feb 21, 2013, 8:43:02 PM2/21/13
to oauth...@googlegroups.com
Can you please also try removing the braces around the client_secret, as Breno suggested?

M T

unread,
Feb 21, 2013, 9:02:52 PM2/21/13
to oauth...@googlegroups.com
No luck, still the same error.

Vladimir Kolovski

unread,
Feb 21, 2013, 9:36:18 PM2/21/13
to oauth...@googlegroups.com
There is something off in how your POST request is generated. I tried a simple POST using curl, and the request at least got parsed by the server (I did get an invalid_grant error though).

curl --data "code=4/KgR6BYpBxMZy0XMxB0lBJNrpm4PE.0gc2lQa60qwRaDn_6y0ZQNgCIn-jeQI&client_id=63149316502.apps.googleusercontent.com&client_secret=ZKvGB-1llx0ML6bK1paoN3nW&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code"  https://accounts.google.com/o/oauth2/token

Reply all
Reply to author
Forward
0 new messages