Rails 3 authentication with OpenID, Twitter or Facebook

user142913 picture user142913 · Apr 26, 2010 · Viewed 9.4k times · Source

Can you suggest some working example of it? I tried Authlogic and Devise withous success.

Answer

johnmcaliley picture johnmcaliley · Aug 16, 2010

UPDATE - June 2011 - I have been using the omniauth gem recently and I think it is a better solution than using the gems suggested in this answer. It works well with Devise and will give you everything you need in one gem. I created an engine that combines Devise and Omniauth and adds a controller to handle the callbacks. I have quite a few changes planned for the gem and right now I don't consider it a stable plugin, but you may be able to reuse some of the code in the gem: https://github.com/charlotte-ruby/devise_omniauth_engine/blob/master/app/controllers/users/omniauth_callbacks_controller.rb


I recently got this working on Rails 3 (with some problems using OpenID). I don't have a complete working example that you can look at on github, but here is what I am using... all of which have examples in the readme files.

Facebook - fbgraph. Unlike Facebooker, it uses the most recent Facebook API. And the source is very easy to understand if you feel like taking a look at the inner workings. Look at the authentication example in the readme. Dead simple.

Twitter - twitter_oauth Again, check out the readme authentication example. This was fairly easy to set up too.

OpenID - rails/open_id_authentication uses ruby-openid gem, but this repo itself is not a gem, so you will have to drop the code into your app or put in your plugin directory. Take a look at their example in the readme and also inspect the source closely to understand what is going on (its only 130 lines of code). I modified a good bit of it to get it to work with my authentication plugin, but I ran into some problems making it work with both Simple Registration and Attribute Exchange at the same time... but you might be able to get it to work out of the box if the rdoc example is suitable for your app.

Let me know if you have any specific questions on these. I ran into a few problems I was able to resolve with all 3 when I was setting this up.