access token - Google OAuth 2.0 returns invalid redirect_uri_mismatch when getting access_token -
i trying exchange oauth one-time use code got client-side app access token , refresh token on server. response is:
{ "error" : "redirect_uri_mismatch" }
my post request is:
post /o/oauth2/token http/1.1 host: accounts.google.com content-type: application/x-www-form-urlencoded code={my code}& client_id={my client id}& client_secret={my client secret}& grant_type=authorization_code
i have checked client id , client secret against in api console , match.
i one-time use code on client following java code:
static final list<string> scopes = arrays.aslist(new string[]{"https://www.googleapis.com/auth/plus.login","https://www.googleapis.com/auth/userinfo.email"}); string scope = string.format("oauth2:server:client_id:%s:api_scope:%s", server_client_id, textutils.join(" ", scopes)); final string token = googleauthutil.gettoken(c, email, scope);
i have redirect_uri in api console, since trying use cross-client authorization (as described here), deliberately left out of post request required:
when exchanges code tokens, should not include “redirect_uri” argument in post.
any idea on doing wrong?
it turns out "should not include 'redirect_uri' argument in post" not mean omit redirect_uri field. instead means redirect_uri field should have empty value.
my new, working post is:
post /o/oauth2/token http/1.1 host: accounts.google.com content-type: application/x-www-form-urlencoded code={my code}& client_id={my client id}& client_secret={my client secret}& redirect_uri=''& grant_type=authorization_code
Comments
Post a Comment