【问题标题】:Oauth facebook with ruby on rails 5.2.5Oauth facebook 与 ruby​​ on rails 5.2.5
【发布时间】:2021-12-04 13:00:37
【问题描述】:

两天以来,我尝试使用 devise 在 ruby​​ on rails 上进行 Login with Facebook,但它返回 NULL 作为电子邮件的值。我阅读了很多关于 stackoverflow 的文章,但其中很多都是几年前的文章,没有一篇对我有用。感谢您的帮助。
Here is the message in my console when i choose my facebook account

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。
  • 你好。谢谢,但我找到了解决方案。事实上,在我的授权请求期间,由于没有与我用于登录的 facebook 帐户关联的电子邮件,它返回给我 NULL。最后,我使用正确的用户名进行管理。

标签: ruby-on-rails oauth facebook-oauth devise-token-auth


【解决方案1】:
def self.from_omniauth(auth)

unless auth.info.email
  auth.info.email = "#{auth.info.name.split(' ').join}@facebook.com"
end

user = User.where("email= ?", auth.info.email).first
puts auth.info.picture
puts auth.info.name
puts auth.info.email
if user
  return user
else
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
    user.email = auth.info.email
    user.password = Devise.friendly_token[0, 20]
    user.name = auth.info.name   # assuming the user model has a name
    # user.image = auth.info.image # assuming the user model has an image
    # If you are using confirmable and the provider(s) you use validate emails, 
    # uncomment the line below to skip the confirmation emails.
    user.skip_confirmation!
    user.uid = user.uid
    user.provider = user.provider
  end
end

【讨论】:

    猜你喜欢
    • 2015-03-03
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多