Search code examples
rubyoauthomniauth

How do you change the name of the GoogleOauth2 omniauth provider name?


I am using the Google Omniauth gem here and need to provide two instances of it so I can have them ask for a different set of permissions. I have this working with an equivalent Facebook gem using this guide. Doing the same thing doesn't work with the Google gem. Does anyone know what I can do to make this happen?


Solution

  • OK, I figured it out. For some reason, the Google Oauth2 gem doesn't work with the provider name as a symbol, but will take the class name. So I am able to solve this problem with this:

    # initializers/omniauth.rb
    module OmniAuth::Strategies
      class GoogleIntegration < GoogleOauth2
      end
    end
    
    Rails.application.config.middleware.use OmniAuth::Builder do
      provider OmniAuth::Strategies::GoogleIntegration, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
        {
          ...
        }
    end