对我来说,这将是长的.
我在用着:
Ruby on Rails 4
> devise 3.0.3
> omniauth(1.1.4)
> omniauth-facebook(1.4.1)
> omniauth-twitter(1.0.0)
我最近设置了我的omniauth-facebook,一切都正常.现在我想添加omniauth-twitter,但不知何故我搞砸了,很糟糕.
1.设置我的Omniauth-Facebook我做了这个(简而言之):
gem 'omniauth' gem 'omniauth-facebook'
2.)将“provider”和“uid”列添加到我的User模型中.
3.)接下来,我在config / initializers / devise.rb中声明了提供者:
require "omniauth-facebook" config.omniauth :facebook,"App_ID","App_Secret",{:scope => 'email,offline_access',:client_options => {:ssl => {:ca_file => 'lib/assets/cacert.pem'}},:strategy_class => OmniAuth::Strategies::Facebook}
我编辑了我的Model User.rb
# Facebook Settings def self.find_for_facebook_oauth(auth,signed_in_resource = nil) user = User.where(provider: auth.provider,uid: auth.uid).first if user.present? user else user = User.create(first_name:auth.extra.raw_info.first_name,last_name:auth.extra.raw_info.last_name,facebook_link:auth.extra.raw_info.link,user_name:auth.extra.raw_info.name,provider:auth.provider,uid:auth.uid,email:auth.info.email,password:Devise.friendly_token[0,20]) end end
:omniauth_providers => [:facebook]
我编辑的路线:
devise_for :users,:controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
结束
虽然这对Facebook来说完美无暇,但我已经尝试了好几个小时,以使其能够在Twitter上工作,而且我根本无法想像出来.
如果有人在这方面有经验,或者只是知道解决方案可以帮助我设定这个,我会很感激:)
谢谢你们,对于这篇长篇文章,我很抱歉.
此外
Twitter不提供:电子邮件属性,所以我必须拆分我的用户注册过程我猜?
我的用户模型中的Twitter动作
# Twitter Settings def self.find_for_twitter_oauth(auth,signed_in_resource=nil) user = User.where(:provider => auth[:provider],:uid => auth[:uid]).first unless user user = User.create(:first_name => auth[:name],:user_name => auth[:screen_name],:provider => auth[:provider],:uid => auth[:uid],:password => Devise.friendly_token[0,20] ) end user end # build auth cookie hash for twitter def self.build_twitter_auth_cookie_hash data { :provider => data.provider,:uid => data.uid.to_i,:access_token => data.credentials.token,:access_secret => data.credentials.secret,:first_name => data.name,:user_name => data.screen_name,} end
我必须迁移一个可确认的用户 – > How To: Add :confirmable to Users
我的形式的问题,(至少现在得到这个poing