Ken Stipek
Ken Stipek

Reputation: 1522

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?

Upvotes: 1

Views: 735

Answers (3)

Christopher Oezbek
Christopher Oezbek

Reputation: 26293

I think in contrast to CaioEPS, it does not work in all places as intended unless you do it like this:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_integration,
           ENV["GOOGLE_CLIENT_ID"],
           ENV["GOOGLE_CLIENT_SECRET"],
           name: :google_integration,
           strategy_class: OmniAuth::Strategies::GoogleIntegration
end

At least if you use Devise

Upvotes: 0

CaioEPS
CaioEPS

Reputation: 61

A couple of years late, but here's now the proper way of doing it:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider OmniAuth::Strategies::GoogleIntegration,
           ENV["GOOGLE_CLIENT_ID"],
           ENV["GOOGLE_CLIENT_SECRET"],
           name: 'google_integration' # <=== Use the name option.
end

Upvotes: 1

Ken Stipek
Ken Stipek

Reputation: 1522

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

Upvotes: 0

Related Questions