问题描述
我正在尝试使用Omniauth为现有的Rails 2.2应用程序实现Facebook和Twitter身份验证.到目前为止,我还无法找到有关如何在Rails 2.2中执行此操作的任何建议-因此出现了这个问题.我有两个问题要问-
I am trying to implement Facebook and Twitter authentication using Omniauth for an existing Rails 2.2 application. So far I have been unable to find any advise on how to do this in Rails 2.2 - hence this question. I have two questions to ask -
-
我了解从2.3开始引入了对Rails的Rack支持,并且我认为OmniAuth需要Rack.那么甚至可以在Rails 2.2网站上使用OmniAuth,为什么?
I understand Rack support for Rails was introduced from 2.3 and I believe Rack is needed for OmniAuth. So is it even possible to use OmniAuth on a Rails 2.2 website and why ?
如果可以实现OmniAuth-您将如何实现?
If it is possible to implement OmniAuth - how would you do it ?
推荐答案
您不能使用默认的config.gem"omniauth" ...使其正常工作,我做了以下工作:
You can't use the default config.gem "omniauth" ... to get it working i did the following:
1. 手动安装omniauth
sudo gem install omniauth
2.在config/environment.rb文件中的 Rails初始化程序之前进行此操作.
2.Require it before the Rails Initializer in the config/environment.rb file.
require 'omniauth'
Rails::Initializer.run do |config| ....
3.在development.rb文件中,我添加了以下配置
3.In development.rb file i've added the following configuration
config.middleware.use OmniAuth::Builder do
provider :facebook, "XXx", "YYYY", :scope => % (email user_birthday publish_stream offline_access)
end
在此处添加任意数量的提供程序....其他所有功能都应按预期运行.
Add as many providers as you want here .... everything else should work as expected.
这篇关于您如何在Rails 2.2上实现OmniAuth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!