6
votes

Well I am sorry to publish such a lame question but I have managed to use omniauth with facebook, twitter and even linkedin, but I am still unable to do it with google omniauth 2.0, I found that the issue is related to the callback URI (I must add that I am testing with a local enviroment [localhost]), so I have tried to change the URI in the following ways

http:127.0.0.1:3000/auth/google_oauth2/callback/
http:127.0.0.1:3000/auth/google_oauth2/callback
https:127.0.0.1:3000/auth/google_oauth2/callback/
https:127.0.0.1:3000/auth/google_oauth2/callback
http:localhost:3000/auth/google_oauth2/callback/
http:localhost:3000/auth/google_oauth2/callback *
https:localhost:3000/auth/google_oauth2/callback/
https:localhost:3000/auth/google_oauth2/callback

so far I have tried with each one individually and none of these worked, it looks like the one marked with a * is the one being returned on my browser, but still receiving

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

I am therefor looking for an answer on how to perform this authentication or how to set the callback URI properly for a localhost callback. thanks in advance.

BTW: I am using Rails 4 and omniauth, omniauth-google-oauth2 gems BTW2: I have removed the "//" so these won't be treated like links

  • Additional and related question is, how do I add multiple URIs on the redirect list? I have tried to add them separated by "," or simply with a blank space, as none have worked, then I don't really know what would be the propper way.
3
Looks like this is a duplicate of stackoverflow.com/a/20732762/325564Tadas T
I tried to do something like that, but it didn't work, I already manage to make it work, with a single URI, but I can't have it working with multiple URI, but thanks thoughWiston Coronell
@Coronellx would you mind sharing your solution. I'm running into this same problem and the aforementioned post didn't work for me either.Carl Edwards

3 Answers

1
votes

make sure you make the access type online

config.omniauth :google_oauth2, "[my key]", "[secret]", {access_type: 'online'}
1
votes

I guess you should use

http://localhost:3000/users/auth/google_oauth2/callback

(you missed users in the middle)

0
votes

This code works for me. Using Google Drive API in more than one environment. your 'AUTHORIZED REDIRECT URIS' should be as shown below(i am using google, yours could be google_oauth2. Changed in provider option for omniauth config file). Every URI on new line.

http://localhost:3000/auth/google/callback
https://staging_server/auth/google/callback
https://production_server/auth/google/callback

My client_id, client_secret are in 'config/google_client.yml'. Your 'omniauth.rb' file in 'config/initializers' should be as follows

google_client =  YAML.load_file("#{Rails.root.join('config/google_client.yml')}")
ENV['GOOGLE_APP_NAME'] = google_client['APP_NAME']
ENV['GOOGLE_CLIENT_ID'] = google_client['CLIENT_ID']
ENV['GOOGLE_CLIENT_SECRET'] = google_client['CLIENT_SECRET']
ENV['GOOGLE_CLIENT_SCOPE'] = google_client['CLIENT_SCOPE']

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
    { name: "google",
      scope: ENV['GOOGLE_CLIENT_SCOPE'],
      prompt: "consent"
    }    
end

OmniAuth.config.on_failure = SomeController.action(:oauth_failure)

Hope this helps you.