29

I followed this basic tutorial, but I get:

Eroare:redirect_uri_mismatch The redirect URI in the request: urn:ietf:wg:oauth:2.0:oob did not match a registered redirect URI

In my googlings I understand there is something wrong in some settings I made in API Console. I enabled Drive API and I made some settings in table API Access. I take the Client ID and client secret and I put these 2 values in client source but I do not know what to put in the Redirect URI.

What should contain the Redirect URIs?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
user1540471
  • 421
  • 2
  • 5
  • 7
  • 1
    The quickstart guide _completely_ leave out this key fact out! thanks everyone! – Ben Mar 29 '14 at 19:31

4 Answers4

38

The URI urn:ietf:wg:oauth:2.0:oob is a special URI used to identify out-of-browser applications, i.e. non-web applications (desktop, mobile, command line, etc.).

When you create the credentials in the APIs Console, make sure you select "Installed Application" as the application type and the redirect URI will automatically be set as urn:ietf:wg:oauth:2.0:oob and prevent the "redirect_uri_mismatch" when making a request.

Simon East
  • 55,742
  • 17
  • 139
  • 133
Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • According to the [docs](https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi), urn:ietf:wg:oauth:2.0:oob should be used when the response should be returned in the title bar of the browser agent (useful when the client cannot listen on an HTTP port). Thus, this what should be used even in in-browser applications such as browser extensions, in addition to what @Claudio said. – dgh May 07 '13 at 02:33
  • Good thing you mentioned about "Installed Application" in the APIs Console. I got a problem since I was using a "Client ID for web application". It solve my problem now since I was using a "Client ID for native application". Thanks Claudio. – Jerameel Resco Jul 17 '15 at 09:51
  • 6
    2021 Update : "Installed Application" is no more available in google console. You can use 'Desktop Application' instead. – G.Lebret Apr 30 '21 at 15:06
  • @G.Lebret I used Desktop Application for my WinForm app but still get a redirect URI mismatch. The developer console never asked me to set up redirects, nor do I have any since this is a desktop application. Do you know how I could fix this? – Jamie Feb 07 '22 at 21:13
  • 1
    It seems like this no longer works as no matter which type of application is chosen, the return is always "The redirect URI in the request, oob, can only be used by a Client ID for native application. It is not allowed for the WEB client type.". – pat-s Apr 01 '22 at 20:25
8

The URI

urn:ietf:wg:oauth:2.0:oob

is only applicable to those Google client IDs that have been generated for "installed applications".

So to solve your problem you have to create a new Client ID and set Application Type as "Installed application". There you can get ClientId and ClientSecret which you will need.

  1. Create a new Project Here

  2. Select APIs from the left side bar and make sure Drive SDK is ON

  3. Go to Credientials below APIs ,tap on "CREATE NEW CLIENT ID"

  4. Select Installed application and type as iOS and provide Bundle ID (or simply choose "Other")

  5. Copy Client ID & Client secret to use that in your application.

The redirect URI is automatically generated and should prevent the error you are getting.

Simon East
  • 55,742
  • 17
  • 139
  • 133
Jayaprada
  • 944
  • 8
  • 11
  • This doesn't work for me when I used Desktop application in Google console with my C# WinForm app. I get a URI mismatch error from Google for an IP address with a port that changes everytime I run the app. Do you know any workarounds for this? – Jamie Feb 08 '22 at 14:42
3

When you create the credentials in the APIs Console, select "TV and Limited Input devices", this will allow the urn:ietf:wg:oauth:2.0:oob redirect_uri, once it is authenticated, a code will be display for you to paste in the application.

Erisan Olasheni
  • 2,395
  • 17
  • 20
  • 1
    I tried this with my desktop application and got the error `Error 400: invalid_request Localhost URI is not allowed for 'NATIVE_DEVICE' client type.` I'm not sure this is a valid workaround anymore unless I was supposed to add that redirect_uri in my code somewhere? – Jamie Feb 08 '22 at 15:01
-2

For those web applications,please define the URI as your php url as it can handle the token and operate google drive.

ashora
  • 7
  • 3