Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

400 bad request error when exact POST in docs for refresh_token with Google OAuth2.0

I believe I am running the exact POST request in the OAuth docs ( with my credentials ), but I'm getting a 400 error. I was getting a 404 error, but then reset my client_secret and started using the new client_secret and am now getting a bad request error. Any ideas what I am doing wrong?

$.ajax({
    url:'https://www.googleapis.com/oauth2/v4/token',
    data:{
    'code':getParameterByName('code'),
        'client_id':'',
        'client_secret':'',
        'redirect_uri':encodeURI(url+'?mail=tokened'),
        'grant_type':'authorization_code'
    },
    dataType:'json',
    method:'POST',
    success:function(response){console.log(response);}});
like image 325
wordSmith Avatar asked Sep 30 '16 16:09

wordSmith


People also ask

Does Google support oauth2?

Google APIs use the OAuth 2.0 protocol for authentication and authorization. Google supports common OAuth 2.0 scenarios such as those for web server, client-side, installed, and limited-input device applications. To begin, obtain OAuth 2.0 client credentials from the Google API Console.


1 Answers

Most probably the redirect_uri value that you send is off; it should be exactly the URL that you sent in the authorization request i.e. the redirect to the authorization endpoint earlier.

like image 197
Hans Z. Avatar answered Oct 19 '22 05:10

Hans Z.