1

我使用登录系统的设计实现了omniauth 和facebook 插件。

但是,似乎同一个 facebook 帐户会返回不同的令牌uid

我该如何处理 Rails 中的这种情况。

我设计的新方法有副作用吗?

我打算只使用 facebook omniauth 作为登录我的系统的唯一方式。

原始创建用户方法

def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
    user.provider = auth.provider
    user.uid = auth.uid
    user.email = auth.info.email
    user.password = Devise.friendly_token[0,20]
  end
end

新设计的方法

def self.from_omniauth(auth)
  where(email: auth.email).first_or_create do |user|
    user.provider = auth.provider
    user.uid = auth.uid
    user.email = auth.info.email
    user.password = Devise.friendly_token[0,20]
  end
end

样本文件

{
  "_id": ObjectId("55bf803b69702d0603000000"),
  "email": "sample@gmail.com",
  "encrypted_password": "5a2U.62pm6.fsdfdsfdsvNrf.akZ4la45ixpgqB20n6uu",
  "sign_in_count": 4,
  "provider": "facebook",
  "uid": "113569521332134112514",
  "reset_password_token": null,
  "reset_password_sent_at": null,
}

{
  "_id": ObjectId("55c157a5506f638652000000"),
  "email": "sample@gmail.com",
  "encrypted_password": "$sdfgg,so51lkpe7P5DDKwz3hTrqFE7MsfRw0lEa",
  "sign_in_count": 1,
  "provider": "facebook",
  "uid": "10000014141261376741",
}
4

0 回答 0