2

I have been attempting to add google auth to my signup page and have followed the steps in the guide but once I sign in to my google account, I get redirected to localhost:3000/# and have the following error in my console:

E, [2018-01-02T18:21:05.351019 #57341] ERROR -- omniauth: (google_oauth2) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch: 

{ "error" : "redirect_uri_mismatch" }

I have tried all the solutions in this existing stackoverflow thread but none of these solutions that have worked for these users have worked for me.

My devise.rb:

Devise.setup do |config|
config.stretches = Rails.env.test? ? 1 : 11
config.extend_remember_period = true
config.password_length = 2..72
config.sign_out_all_scopes = false
config.sign_out_via = :get



 OmniAuth.config.full_host = Rails.env.production? ? 
  'http://localhost:3000'
    config.omniauth(:facebook,
                  Rails.application.secrets.facebook_app_id,
                  Rails.application.secrets.facebook_api_key,
                  image_size: :large)
     config.omniauth(:google_oauth2,
                  Rails.application.secrets.google_client_id,
                  Rails.application.secrets.google_client_secret,
                  {:redirect_uri => 
     "http://localhost:3000/users/auth/google_oauth2/callback"}
     )
     require('devise/orm/active_record')
 end

routes.rb

  r.devise_for(:users,
             only:        :omniauth_callbacks,
             controllers: {omniauth_callbacks: :omniauth})

I have also added the following redirect uris to my google developers console:

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

Thank you in advance for your answers!

James Chou
  • 41
  • 1
  • 6

1 Answers1

0

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

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
}

Hope to help

fool-dev
  • 7,671
  • 9
  • 40
  • 54
  • I didn't use any parameters for scope, prompt, or image_size but I added them just to see if it would change anything. Still nothing. – James Chou Jan 06 '18 at 22:11