加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails 3上使用Omniauth检索Google个人资料图

发布时间:2020-12-17 03:45:28 所属栏目:百科 来源:网络整理
导读:我正在使用Omniauth开始一个新的Rails 3应用程序,通过Facebook,Twitter和Google进行身份验证.我可以轻松地从Facebook和Twitter获取用户的头像,但如果存在,则无法找到从Google检索它的方法. 这是我用来构建身份验证哈希的代码: omniauth['user_info']['email
我正在使用Omniauth开始一个新的Rails 3应用程序,通过Facebook,Twitter和Google进行身份验证.我可以轻松地从Facebook和Twitter获取用户的头像,但如果存在,则无法找到从Google检索它的方法.

这是我用来构建身份验证哈希的代码:

omniauth['user_info']['email'] ? @authhash[:email] =  omniauth['user_info']['email'] : @authhash[:email] = ''
omniauth['user_info']['name'] ? @authhash[:name] =  omniauth['user_info']['name'] : @authhash[:name] = ''
omniauth['uid'] ? @authhash[:uid] = omniauth['uid'].to_s : @authhash[:uid] = ''
omniauth['provider'] ? @authhash[:provider] = omniauth['provider'] : @authhash[:provider] = ''

在Twitter和Facebook上,如果未提供,则下一行获取头像或设置为默认值:

omniauth['user_info']['image'] ? @authhash[:image] =  omniauth['user_info']['image'] : @authhash[:image] = 'avatar.jpg'

这不适用于Google,我找不到任何相关文档.

有任何想法吗?

非常感谢!

解决方法

尝试’Omniauth Google OAuth2策略’,其中提交声明:

Returns name,first_name,last_name,image,email in info with :scope => ‘userinfo.email,userinfo.profile’

您可以查看提交here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读