zquestz / omniauth-google-oauth2

Oauth2 strategy for Google
1.45k stars 414 forks source link

Custom redirect_uri prevents callback phase from starting #373

Closed helderasmoreira closed 3 years ago

helderasmoreira commented 5 years ago

configuration

Pretty vanilla Rails 6 application with the latest version of this gem.

description

I've been exploring the possible options that one can pass to the provider when configuring and I've found what I believe is a weird behaviour related to the redirect_uri.

If I set it in my configuration for something else than the default (/auth/google_oauth2/callback):

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
    {
      redirect_uri: 'http://localhost:3000/example/route',
    }
end
get '/example/route', to: 'home#google_callback'

this seems to prevent the Callback phase from initiating. The request is redirected to my redirect_uri but since there is no callback phase, there is no exchange of the authorization code for the access token and the process seems to hang mid way, leaving request.env['omniauth.auth'] to be nil.

If I were to just switch the above to use the default value (or remove the hash):

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
    {
      redirect_uri: 'http://localhost:3000/auth/google_oauth2/callback',
    }
end
get '/auth/google_oauth2/callback', to: 'home#google_callback'

things change and the callback phase is initiated as expected, the code is exchanged for a token and request.env['omniauth.auth'] is set properly.

Am I missing something? Has anyone customized the redirect_uri and has a different experience perhaps?

zquestz commented 4 years ago

I am also seeing issues in my testing. Looking into it more now, seems the redirect_uri specified is not the one being sent to google.

IgPugliese commented 4 years ago

i'm having the same problem, redirect_url is not working

ddlogesh commented 3 years ago

I'm also have the same problem, redirect_url is not working as expected

zquestz commented 3 years ago

I have just tested against master and can confirm that redirect_uri is working. Please let me know if you still have issues.

andrewdang17 commented 2 years ago

@heldersantosmoreira were you able to get this to work? I am running into this issue as well. I tried passing a redirect_uri param as well but it seems to only work with the default

helderasmoreira commented 2 years ago

@andrewdang17 to be honest I found no solution at the time and ended up giving up and using the default value. Not sure what's the situation in the latest version.

Saoma1 commented 1 year ago

This still seams to be an issue, running rails 7.0.4 & omniauth-google-oauth2 1.1.1 Has anyone found a solution?