简体   繁体   中英

Google OmniAuth for rails giving error “Missing required parameter: client_id”

I need some help.

I have followed all the steps correctly to enable a Google sign in using omniauth.

My Config/Initializers/omniauth.rb

     require 'omniauth-google-oauth2'
     require 'dotenv'

        Rails.application.config.middleware.use OmniAuth::Builder do
        provider :google_oauth2,
        ENV["GOOGLE_APP_ID"],
        ENV["GOOGLE_APP_SECRET"]
.......

    end 

My routes are correct:

  get    '/auth/google_oauth2/callback', to: 'sessions#googleAuth'
  get    'auth/failure',                 to: redirect('/')
  get    'signout',                      to: 'sessions#destroy', as: 'signout'

I have saved credentials properly.

However I am still getting the following error when I click on Google Sign In to redirect to access.

The error is as follows:

  1. That's an error.

Error: invalid_request

Missing required parameter: client_id

Learn more

Request Details access_type=offline client_id= prompt=consent redirect_uri= http://localhost:3000/auth/google_oauth2/callback response_type=code

Why am I getting the missing client_id error, when my project is properly set on the Google Console, everything else is fine.

Please help me get around this.

Thank you!

Hey thanks all for the comments.

I was able to resolve it by adding

Dotenv.load 

to the Omniauth.rb

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM