【发布时间】:2014-08-19 01:30:15
【问题描述】:
我在我的 Rails 3.2 应用程序中使用 Devise 进行身份验证,但无法配置 omniauth-facebook 以获取新用户的电话号码。
首先:我什至不确定是否有可能获得电话号码,所以如果是这种情况并且有人肯定知道,我会很乐意确认。
从https://github.com/mkdynamic/omniauth-facebook 看来,默认情况下“电话”是 FB auth 哈希的一部分,尽管一般的 Omniauth 架构确实有 .info.phone(当然不是必需的)。所以我的第一个想法是这是一个 FB 权限问题。不过,我不确定要使用什么权限,因为Permissions with Facebook Login 页面没有说明在哪里可以找到电话值(也许这意味着不可能?)。
我将phone 作为用户模型的必需属性,因此当我尝试通过 FB 获取它时,新对象永远不会存在。无需查找电话号码即可正常工作。
我的配置文件:
# /config/initializers/devise.rb
config.omniauth :facebook, 'FACEBOOK_APP_ID', 'FACEBOOK_APP_SECRET', scope: 'email,public_profile', display: 'page'
在我的用户模型中:
# user.rb
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.phone = auth.extra.raw_info.phone # have also tried auth.info.phone
end
end
提前感谢您提供的任何帮助!
【问题讨论】:
标签: ruby-on-rails facebook authentication devise omniauth