Getting "Error: redirect_uri_mismatch" with google_oauth2

alexchenco picture alexchenco · Nov 3, 2012 · Viewed 11.6k times · Source

The URL's seem right (Last updated them yesterday):

enter image description here

The files too:

omniauth.rb:

provider :google_oauth2, 'MY_CLIENT_ID.apps.googleusercontent.com', 'MY_CLIENT_SECRET',
           :scope => 'https://mail.google.com/mail/feed/atom/'

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/auth/google_oauth2/callback did not match a registered redirect URI

header.html.erb

<li><%= link_to "Sign in with Google", "auth/google_oauth2" %></li>

routes.rb:

match '/auth/:provider/callback', to: 'sessions#omniauth_create'

But I'm getting this:

> Error: redirect_uri_mismatch The redirect URI in the request:
> http://localhost:3000/auth/google_oauth2/callback did not match a
> registered redirect URI

(Twitter and Facebook OmniAuth are working perfectly)

Not sure what is the problem. Any usggestions to fix this?

EDIT

I changed the URI to http...:

enter image description here

But still getting the same error.

Answer

RocketDonkey picture RocketDonkey · Nov 3, 2012

It looks like the request is hitting http://localhost:3000/auth/google_oauth2/callback, but your specified redirect URI matching the similar pattern is for https. Adding http://localhost:3000/auth/google_oauth2/callback to your list of redirects may potentially solve that issue.

EDIT: Another potential fix is including a trailing / in the corresponding redirect URIs, which appeared to work in this case.