Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a new strategy for Omniauth, but Omniauth can't find it

I'm new to Rails and to Omniauth, so sorry in advance for the dumb question.

I'm trying to do an Omniauth strategy for the Deezer website. http://www.deezer.com/en/developers/simpleapi/oauth

First, I set up a basic rails application to test the Facebook strategy. Here is my code in Github : https://github.com/geoffroymontel/omniauth-test

And it works fine. Good.

Then I added those files in my app lib directory

lib/omniauth-deezer.rb
lib/omniauth/deezer.rb
lib/omniauth/deezer/version.rb
lib/omniauth/deezer/strategies/deezer.rb

and added

provider :deezer, ENV['DEEZER_APP_ID'],
ENV['DEEZER_APP_SECRET'], :perms => 'basic_access,email'

in

config/initializers/omniauth.rb

But when I start the app with

rails s

I get the following error message

/home/geoffroy/.rvm/gems/ruby-1.9.2-p290@rails3tutorial2ndEd/gems/omniauth-1.0.2/lib/omniauth/builder.rb:33:in `rescue in provider': Could not find matching strategy for  :deezer. You may need to install an additional gem (such as omniauth-deezer). (LoadError) from /home/geoffroy/.rvm/gems/ruby-1.9.2-p290@rails3tutorial2ndEd/gems/omniauth-1.0.2/lib/omniauth/builder.rb:30:in `provider'

Thanks for your help

Best

Geoffroy

like image 306
geoffroy Avatar asked Feb 06 '12 11:02

geoffroy


3 Answers

I added

require 'omniauth-deezer'

in initializers/omniauth.rb and it worked.

I don't really understand why I need it and Facebook doesn't.

like image 69
geoffroy Avatar answered Nov 09 '22 00:11

geoffroy


In the Upgrading to 1.0 doc it is mentioned that Omniauth needs a gem for every provider now, so you'll have to move your provider to a gem eventually.

like image 28
wintersolutions Avatar answered Nov 08 '22 22:11

wintersolutions


For future reference, if you want to add your own omniauth strategy, add this to your gemfile

gem 'omniauth-mystrategy', :path => '~/full-path-to-the-omniauth-folder/'

You´ll be using the local repository feauture of the gemfiles. In the official bundler page you´ll see how to use remote repos also.

http://gembundler.com/v1.3/gemfile.html

like image 2
Guillermo Siliceo Trueba Avatar answered Nov 08 '22 23:11

Guillermo Siliceo Trueba