Ruby on Rails - Could not find a suitable strategy for: google_oauth2

I have

gem 'omniauth-google_oauth2' 

in my gemfile. After that I installed the package. He is mistaken in saying:

ruby-1.9.3-p0 / gems / OmniAuth -1.0.2 / Library / OmniAuth / builder.rb: 33: in `rescue in provider ': could not find a suitable strategy for: Google_oauth2. You may need to install an additional stone (for example, OmniAuth-google_oauth2). (LoadError)

What am I missing? Any ideas please.

+6
source share
3 answers

Use

 gem 'omniauth-google-oauth2' 

Change the last underscore to a hyphen.

+9
source

The problem is caused by the way OmniAuth renders provider names:

OmniAuth::Utils.camelize(:google_oauth2.to_s) => GoogleOAuth2

However, the provider is actually GoogleOAuth2 - fully qualified - OmniAuth::Strategies::GoogleOauth2

So, the solution is to use a fully qualified class: OmniAuth::Strategies::GoogleOauth2

 Rails.application.config.middleware.use OmniAuth::Builder do provider OmniAuth::Strategies::GoogleOauth2, ENV["KEY"], ENV["SECRET"] end 
+6
source

Using the Ben W solution made the server running, but screwed it up as I do the routes. I used this in config/initializers/omniauth.rb

 :google_oauth2, "[KEY]", "[SECRET]" 

Now my google path google /auth/google_oauth2

0
source

Source: https://habr.com/ru/post/908918/


All Articles