Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am getting Error: redirect_uri_mismatch in rails 5 even all the uris are setup correctly. #250

Closed
singh-ashutosh-007 opened this issue Sep 18, 2016 · 19 comments

Comments

@singh-ashutosh-007
Copy link

No description provided.

@zquestz
Copy link
Owner

zquestz commented Sep 18, 2016

I will need more details. Please provide logs, and describe your setup.

@singh-ashutosh-007
Copy link
Author

singh-ashutosh-007 commented Sep 19, 2016

gem 'omniauth-google-oauth2'

In devise.rb
config.omniauth :google_oauth2, ENV["google_app_id"], ENV["google_secret"], {
:scope => 'email,profile'
}

redirect-uri
http://localhost:3000/users/auth/google_oauth2/callback

Now when trying to get login with google I am getting:
400

Redirect uri mismatch error.

Logs are fine nothing wrong in backend here are my logs:

Started GET "/users/sign_in" for 127.0.0.1 at 2016-09-19 07:33:52 -0700
Processing by Devise::SessionsController#new as HTML
Rendering users/sessions/new.html.erb within layouts/application
Rendered users/shared/_links.html.erb (3.0ms)
Rendered users/sessions/new.html.erb within layouts/application (303.5ms)
Rendered layouts/_top_nav.html.erb (0.9ms)
Completed 200 OK in 482ms (Views: 355.7ms | ActiveRecord: 109.7ms)

Started GET "/users/auth/google_oauth2" for 127.0.0.1 at 2016-09-19 07:33:54 -0700
I, [2016-09-19T07:33:54.359644 #5432] INFO -- omniauth: (google_oauth2) Request phase initiated.
Started GET "/users/auth/google_oauth2" for 127.0.0.1 at 2016-09-19 07:33:56 -0700
I, [2016-09-19T07:33:56.719362 #5432] INFO -- omniauth: (google_oauth2) Request phase initiated.

FOR YOUR INFORMATION
Login with facebook is working perfectly

@zquestz
Copy link
Owner

zquestz commented Sep 19, 2016

Now to just be clear, you did add the authorized redirect URI's to Google? You must make sure they have been added here: https://console.developers.google.com/

Just make sure you have edited the Authorized Redirect URIs in the Credentials section.

@singh-ashutosh-007
Copy link
Author

@zquestz: Already mentioned All the uri are correct. Also implemented omniauth-facebook which is working perfectly.
Again saying I have edited the Authorized Redirect URIs in the Credentials section.

@zquestz
Copy link
Owner

zquestz commented Sep 20, 2016

Can you try with 127.0.0.1 instead of localhost? Curious if that resolves your issue. Sometimes localhost can resolve in odd ways and trigger this error.

@singh-ashutosh-007
Copy link
Author

Already tried Still same issue.

@zquestz
Copy link
Owner

zquestz commented Sep 21, 2016

Can you test with the included example application? Just bind it to the same port and confirm that also doesn't work? That way we can make sure your setup is valid and that the issue really is with Rails 5 (which I have working fine locally...)

@spq24
Copy link

spq24 commented Oct 7, 2016

Same error with Rails 5 setup. I am testing locally with ngrok setup and it worked fine the first time around, but when I just went to do it with a new ngrok link it doesn't work. It's like it's caching the original link for the redirect_uri. I made sure the link was updated in Google's developer console so it's an error from there.

Old ngrok link: http://f36f7183.ngrok.io
new one: http://a5714723.ngrok.io

But when I go to sign in with Google here's the link it takes it to:
https://accounts.google.com/AccountChooser?continue=https://accounts.google.com/o/oauth2/auth?access_type%3Doffline%26scope%3Demail%2Bprofile%26response_type%3Dcode%26redirect_uri%3Dhttp://f36f7183.ngrok.io/users/auth/google_oauth2/callback%26state%3Dd9cd41fe40e8308ef7fa5af38c3022e6623a06efd688731f%26client_id%3XXX%26from_login%3D1%26as%3D6ef3b6caeac2114&btmpl=authsub&scc=1&oauth=1

As you can see it's still showing the old redirect_uir in there: 3Dhttp://f36f7183.ngrok.io/users/auth/google_oauth2/callback

which is causing an error with Google since obviously that redirect_uri does not match what's in Google anymore.

Is there a solution? Or do I have to manually over-ride the redirect_uri now?

@zquestz
Copy link
Owner

zquestz commented Oct 7, 2016

There is no caching at all in the gem so I have no idea what could be causing this for you. I would go ahead and over-ride the redirect_uri, but that should not be necessary.

@singh-ashutosh-007
Copy link
Author

singh-ashutosh-007 commented Oct 16, 2016

@zquestz: Did you find any solution?

@zquestz
Copy link
Owner

zquestz commented Oct 16, 2016

I can't replicate this, and I don't do any special handling for the redirect_url. For now I would just pass the correct redirect_uri when passing options to the strategy.

config.omniauth :google_oauth2, "GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET", { :redirect_uri => "YOUR_REDIRECT_URI" }

@nfedyashev
Copy link

nfedyashev commented Oct 24, 2016

One thing that I noticed is that

if my auth path is like user_omniauth_authorize_path(provider: 'gplus') then it works fine.
But if I want to pass some additional parameter, like user_omniauth_authorize_path(provider: 'gplus', foo: 'bar') then I get "Redirect uri mismatch error".
I find this behavior a bit annoying because other oauth providers like Facebook/Twitter/LinkedIn accept those GET parameters(and give them back in response).

I believe it has nothing to do with omniauth-google-oauth2, just the way how Google interprets it.

@Brotakuu
Copy link

Brotakuu commented Oct 28, 2016

Had a similar problem when providing scopes in the devise initializer. But when I remove all options, it works.

config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], {
}

Update: My issue turned out to only appear when the :name option was added. Once removed, this works just fine:

config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], {
    :scope => "email, profile",
    :prompt => "select_account",
    :image_aspect_ratio => "square",
    :image_size => 50
  }

@zquestz
Copy link
Owner

zquestz commented Oct 28, 2016

Thanks for the feedback @Brotakuu. This will be useful for people to know!

@zquestz
Copy link
Owner

zquestz commented Oct 31, 2016

@ashutosh-singh-rawat did you get it working? Safe to close this?

@zquestz
Copy link
Owner

zquestz commented Nov 11, 2016

Assuming issue is resolved. Can reopen if needed.

@zquestz zquestz closed this as completed Nov 11, 2016
@rorong
Copy link

rorong commented Nov 24, 2016

@zquestz: Its working fine.

@waldothedeveloper
Copy link

Hi Josh, I´m trying to include Google Authentication to my app, but I´m getting:
"Not found. Authentication passthru."
I added you as a collaborator to my github repo, could you check what´s wrong?

@duleorlovic
Copy link

duleorlovic commented Dec 8, 2017

Probably the issue is with dependency similar to #204
If you have fixed version gem 'omniauth-google-oauth2', '0.2.5' than you need to fix version of gem 'omniauth-oauth2', '~> 1.3.1'.
Latest versions works fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants