Rails 3 authentication with OpenID, Twitter or Fac

2020-05-12 05:06发布

问题:

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

回答1:

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.



回答2:

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.



回答3:

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



回答4:

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



回答5:

AuthLogic has an OpenID extension.

Also, this may help: http://www.michaelhamrah.com/blog/2009/05/authlogic-and-openid-on-rails/



回答6:

The easiest way I've found to do this is to use RPX NOW service.

You can find a full working example of using it with Rails3 and the RPX NOW gem at github.