How do you implement OmniAuth on Rails 2.2?

六月ゝ 毕业季﹏ 提交于 2019-12-08 13:35:14

问题


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 -

  1. 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 ?

  2. If it is possible to implement OmniAuth - how would you do it ?


回答1:


You can't use the default config.gem "omniauth" ... to get it working i did the following:

1.Install omniauth manually

sudo gem install omniauth

2.Require it before the Rails Initializer in the config/environment.rb file.

require 'omniauth'
Rails::Initializer.run do |config| ....

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.



来源:https://stackoverflow.com/questions/5165544/how-do-you-implement-omniauth-on-rails-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!