24

I am Creating and Authorizing an OAuth Token according to this webpage: https://code.google.com/p/google-mail-oauth2-tools/wiki/OAuth2DotPyRunThrough

But I got this error: redirect_uri_mismatch.

The redirect URI in the request: urn:ietf:wg:oauth:2.0:oob did not match a registered redirect URI
from_login=1
cookie_policy_enforce=false
scope=https://mail.google.com/
response_type=code
access_type=online
redirect_uri=urn:ietf:wg:oauth:2.0:oob
as=-80019291b2cb8ed
display=page
pli=1
client_id=......
authuser=0
hl=en

I thought this might be helpful: Google OAuth 2 authorization - Error: redirect_uri_mismatch

But when I try to register the redirect url to my console, I was told that the url is invalid.

Community
  • 1
  • 1
Cacheing
  • 3,431
  • 20
  • 46
  • 65

13 Answers13

50

The redirect_uri (urn:ietf:wg:oauth:2.0:oob) is only applicable to those Google client ids that have been generated for installed applications. You can go to your console and create a new client id of this type.

oravecz
  • 1,146
  • 11
  • 16
32

Just in case if you're using Google+ javascript button (with web application), you have to put postmessage instead of actual URI. It takes me almost whole day to figure out this, because Google docs doesn't clearly stand it for some reason.

Mike Keskinov
  • 11,614
  • 6
  • 59
  • 87
10

For my web application i corrected my mistake by writing

instead of : http://localhost:11472/authorize/
type :      http://localhost/authorize/
Guven Sezgin Kurt
  • 1,199
  • 11
  • 13
  • So we can have localhost as URI and it will work for published web sites? For live/published web sites, how come a localhost works? Am I missing something here? – Unbreakable Dec 22 '16 at 05:42
  • This is the only solution that actually worked for me. If you are just poking around with the Quick Start then this is what you need to do!!!!! – zypherman Sep 19 '17 at 16:19
7

When you register your app at https://code.google.com/apis/console and make a Client ID, you get a chance to specify one or more redirect URIs. The value of the redirect_uri parameter on your auth URI has to match one of them exactly.

Kathir
  • 1,212
  • 15
  • 25
7

Please note that the 'redirect_uri' value of the Token request need to be the same as the 'redirect_uri' value of the Authorization request.

Fadelovesky
  • 121
  • 2
  • 3
  • exactly, thanks! my problem was that to receive authorization code I used `urn:ietf:wg:oauth:2.0:oob:auto` (*auto*!) but for authorization I didn't know exactly the same uri should be used – Andriy Tylychko Jun 28 '15 at 19:32
5

Lost 4 or 5 hours with this... use 'postmessage' as parameter value, not the real Redirect Uri...

$client->setRedirectUri('postmessage');
DevFdbck
  • 51
  • 1
  • 2
  • i am java guy, but changing redirect uri to postmessage worked for me. two hours spent on this ****. – OGM2 Apr 01 '20 at 11:10
3

For anybody that is still stumped with this problem, you must have the 'Platform' set to 'Native (Windows Mobile, Blackberry, desktop, devices, and more)' when registering your app in the Google Cloud Console, otherwise, it will not let you use 'urn:ietf:wg:oauth:2.0:oob' as the redirect URI.

SameOldNick
  • 2,397
  • 24
  • 33
3

In my case, instead of creating web app, i just chose Other in: OAuth Client ID > Other

and thats it.

Goran Jakovljevic
  • 2,714
  • 1
  • 31
  • 27
1

2015July15 - working signin started causing Error 400 with Error: redirect_uri_mismatch

i posted a solution on a similar SO QUESTION: changed loading script to

<script src="https://apis.google.com/js/client:platform.js?onload=startApp></script>
Community
  • 1
  • 1
tony gil
  • 9,424
  • 6
  • 76
  • 100
0

For my native app, I tried dozens of different things. I finally got it to work by using "redirect_uri=http%3A%2F%2Flocalhost%3A1234" where 1234 is the port number. This has to be identical in the two requests (authorization code and the access token). Notice the use of percent encoding.

Greg Wittmeyer
  • 439
  • 4
  • 14
0

I was getting this error, because I was incorrectly following the steps for installed application flow here

https://github.com/googleads/googleads-python-lib/wiki

instead of the server to server flow.

M3RS
  • 6,720
  • 6
  • 37
  • 47
0

The easiest way is to create the service account.

Create the document using your own account and share it with the service account.

Dharman
  • 30,962
  • 25
  • 85
  • 135
zawhtut
  • 8,335
  • 5
  • 52
  • 76
0

redirect_uri must be an EXACT MATCH on the developers console.

In my case, this was due to a trailing slash( / ).

In the Google Cloud console, I had http://localhost:8080 under the redirect URIs in the list while my code was sending http://localhost:8080/ while making the oAuth call.

Kaushal Dokania
  • 339
  • 3
  • 6