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 %>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.