Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 authentication with OpenID, Twitter or Facebook

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

like image 337
user142913 Avatar asked Apr 26 '10 11:04

user142913


4 Answers

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.

like image 93
johnmcaliley Avatar answered Nov 03 '22 04:11

johnmcaliley


I spent about a week trying (unsuccessfully) to get open_id_authentication working. I was trying to use Authlogic and all the associated gems and plugins. I could not get things working the way I wanted. (Authentication would only work with the :action(/:id) route enabled, but when that was enabled, my other controllers wouldn't work because something in the plugin was stripping the params hash - very frustrating).

However, I was finally able to get OpenID working using Devise (http://github.com/plataformatec/devise) and devise_openid_authenticatable (http://github.com/nbudin/devise_openid_authenticatable). I was able to follow the readme's on both of the pages to get everything working exactly like I wanted it to. Simple. Straight forward. And Rails 3.0 compatible.

like image 32
salt.racer Avatar answered Nov 03 '22 05:11

salt.racer


Devise is built on Warden, which is the correct google term. Search 'warden openid', 'warden oauth' (twitter) and http://github.com/britt/facebook-warden-strategy for facebook

like image 2
Reactormonk Avatar answered Nov 03 '22 03:11

Reactormonk


If you're going to use Facebooker 2, you'll have to upgrade your Rails framework to 3.0. Ayeah Games just went through the process for the game FanSwarm (on Facebook). This is no easy task, but the blog post may give you some insight.

http://www.ayeahgames.com/blog/bid/55099/The-Horror-Upgrading-to-Rails-3

like image 1
Scott Avatar answered Nov 03 '22 04:11

Scott