Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top