views:

62

answers:

2

I have been searching to figure out how exactly to use the oauthable module in the Devise gem for Rails 3. I have come across a couple of questions on here that seem correct, but I was unable to get the implementation working. My end goal is to have both Twitter and Facebook authentication through Devise in my Rails 3 application. Right now I am struggling with what I thought was the "example" in the warden strategy list. I have got this far.

Inside of my devise initalizer I have the following blocks of code in, what I believe, the appropriate places.

manager.oauth(:twitter) do |twitter|
  twitter.consumer_secret = '[secret]'
  twitter.consumer_key  = '[key]'
  twitter.options :site => 'http://twitter.com'
end
manager.default_strategies(:scope => :user).unshift :twitter_oauth        

Warden::OAuth::access_token_user_finder(:twitter) do |access_token|
  User.find_or_create_by(:token => access_token.token, :secret => access_token.secret).tap do |user|
     user ||= User.create!(:access_token => access_token.token, :secret => access_token.secret)
  end
end

I have placed a link on one of my views but all I am getting is an error, OAuth 401 Unauthorized, is this something from Twitter or am I completely missing a step?

+1  A: 

Have you seen OmniAuth for Twitter, FB and other social network authentication integration into devise?

The last two railscast episodes show off an integration.

OmniSocial is another solution built on top of the two.

Joost Schuur
You sir, just made my day.
John Bellone
Glad I could help! I'm fairly new to Rails development, but Ryan's screencasts are a gold mine and seem to crop up every time I want to do something new.
Joost Schuur
A: 

I am going to answer my own question here. I was pointed to take a look at using OmniAuth through the Railscast. I ran into some issues with the session information, so I did some more digging and spoke with the developers of Devise. It seems that they are internally moving towards supporting Omniauth natively in version 1.2 (still in testing).

For my project the answer is to download the latest version of both Warden and Devise which allow some awesome native support for OmniAuth.

The support is detailed in the Wiki page on the devise Github project which goes through how you can add "omniauthable" to your devise_for in your model. It is a very easy process and I am currently using it for several endpoints that OmniAuth makes available.

John Bellone