views:

606

answers:

3

Rails has the rest autho plugin which works well but is there a solution for incorporating twitter, facebook, google, yahoo, etc...

Seems like each on has its own plugin and demands and mixing them is going to be a mess.

This is for logging in users like how Stackoverflow gets things done not for using the robust features of the APIs.

What I want to do is do what stackoverflow did for login but in rails.

A: 

If you got a budget for it, you can check out RPX: https://rpxnow.com/.

keruilin
A: 

It's not too difficult to write your own controller code to connect to each of these services and redirect. For example, to authenticate to twitter using oauth takes two actions and about 20 lines of code total.

Keep the code for each service separate in it's own controller.

def twitter_oauth
  o = Twitter::OAuth.new(your_twitter_consumer_token, your_twitter_consumer_secret, :authorize_path => '/oauth/authenticate', :sign_in => true)
  o.set_callback_url(twitter_cb_url)
  session[:twitter_oauth_request_token] = o.request_token.token
  session[:twitter_oauth_request_secret] = o.request_token.secret
  redirect_to o.request_token.authorize_url
end

def twitter_oauth_cb
  o = Twitter::OAuth.new(your_twitter_consumer_token, your_twitter_consumer_secret, :authorize_path => '/oauth/authenticate', :sign_in => true)
  if params[:denied]
    redirect_to root_url
  elsif params[:oauth_verifier]
    o.authorize_from_request(session[:twitter_oauth_request_token], 
                             session[:twitter_oauth_request_secret],
                             params[:oauth_verifier])
    # look up this user in the db by o.access_token.token 
    # is the user not found? create them, save their token
    # log them in - UserSession.create(user, true)
    redirect_to root_url
  end
end
Jonathan Julian
How 'bout an example? Thanks.
Larry K
Added example code for twitter. It's enough to get you started, but you'll have to plug in your own User lookup and create.
Jonathan Julian
Thanks for the effort, will give it a try
Sam
A: 

I made an implementation of this using authlogic, using the same JQuery OpenID Selector plugin that StackOverflow is using. Works with Google, Yahoo, Facebook, etc. I've been using it for about 3 months and it works quite well. Still a few kinks to workout, it also supports auto-registration.

I'd like to add twitter to future versions and am hoping others will help add some features/bug fixes. ;-) Check it out.

In action:

http://big-glow-mama.heroku.com/

Code:

http://github.com/holden/authlogic_openid_selector_example

holden