Rails Twitter OAuth 策略与 Devise
我一直在寻找如何准确地在 Rails 3 的 Devise gem 中使用 oauthable 模块。我在这里遇到了几个看起来正确的问题,但我无法让实现工作。我的最终目标是在我的 Rails 3 应用程序中通过 Devise 进行 Twitter 和 Facebook 身份验证。现在我正在努力解决我认为是典狱长策略列表中的“示例”。我已经走到这一步了。
在我的设计初始化器内部,我相信在适当的位置有以下代码块。
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
我已经在我的一个视图上放置了一个链接,但我得到的只是一个错误,OAuth 401 未经授权,这是来自 Twitter 的内容还是我完全错过了一个步骤?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否见过将 Twitter、FB 和其他社交网络身份验证集成到设备中的 OmniAuth ?
最后两集 railscast 剧集 展示了集成。
OmniSocial 是建立在两者之上的另一个解决方案。
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.