我在用着:
- Ruby on Rails 4
- 设计 3.0.3
- 全域认证 (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
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}
4.)我编辑了我的模型 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]
5.)我编辑了路线:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
结束
虽然这对 Facebook 来说非常有效,但我现在尝试了几个小时来让它在 Twitter 上工作,我就是想不通。
如果有这方面经验或只知道解决方案的人可以帮助我进行设置,我将非常感激:)
谢谢大家,很抱歉发了这么长的帖子。
此外
Twitter 不提供 :email 属性,所以我猜我必须拆分我的用户注册过程?
我的用户模型中的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
我必须为用户迁移一个可确认的 ->如何:添加:可确认给用户
我的表格的问题,(至少我现在要解决这个问题了:))