0

I want add omniauth with Google on my Rails app but i have error after redirection

ERROR -- omniauth: (google_oauth2) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch: Bad Request
{
  "error": "redirect_uri_mismatch",
  "error_description": "Bad Request"
}

I saw errors about bad redirection uri but not "bad request"

My redirection uri in google console

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

My route

devise_for :clients, controllers: { omniauth_callbacks: 'clients/omniauth_callbacks' }

Gemfile

gem 'omniauth-oauth2'
gem 'omniauth-google-oauth2'
gem "omniauth-linkedin-oauth2"
gem 'omniauth-rails_csrf_protection', '~> 1.0'

devise

  config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], access_type: "online"

my link

<%= link_to "Sign in with Google", client_google_oauth2_omniauth_authorize_path, method: :post %>

1 Answer 1

1

Check your google developer account where you created the credentials. there should be a field named redirect URL where you should place the correct URL. This URL was used to redirect the user from modal opened on login with google.

Sign up to request clarification or add additional context in comments.

1 Comment

I already add my redirect url in credidentials

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.