Search code examples
ruby-on-railsruby-on-rails-5omniauthomniauth-google-oauth2

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!


Solution

  • Hey thanks all for the comments.

    I was able to resolve it by adding

    Dotenv.load 
    

    to the Omniauth.rb