Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - Could not find matching strategy for :google_oauth2

I have got

gem 'omniauth-google_oauth2'

in my Gemfile. Did bundle install after that as well. It errors out saying,

ruby-1.9.3-p0/gems/omniauth-1.0.2/lib/omniauth/builder.rb:33:in `rescue in provider': Could not find matching strategy for :google_oauth2. You may need to install an additional gem (such as omniauth-google_oauth2). (LoadError)

What am I missing? Any ideas please.

like image 891
Kannaiyan Avatar asked Feb 20 '12 18:02

Kannaiyan


2 Answers

Use

gem 'omniauth-google-oauth2'  

Change the last underscore to a hyphen.

like image 121
mrmonroe Avatar answered Sep 24 '22 19:09

mrmonroe


The problem is caused by how OmniAuth camelizes the 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 the fully qualified class: OmniAuth::Strategies::GoogleOauth2

Rails.application.config.middleware.use OmniAuth::Builder do
  provider OmniAuth::Strategies::GoogleOauth2, ENV["KEY"], ENV["SECRET"]
end
like image 21
Ben Walding Avatar answered Sep 21 '22 19:09

Ben Walding