使用Onia上的Omniauth检索Google个人资料图片3

rap*_*cal 4 authentication ruby-on-rails omniauth ruby-on-rails-3

我正在使用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] = ''
Run Code Online (Sandbox Code Playgroud)

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

omniauth['user_info']['image'] ? @authhash[:image] =  omniauth['user_info']['image'] : @authhash[:image] = 'avatar.jpg'
Run Code Online (Sandbox Code Playgroud)

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

有任何想法吗?

非常感谢!

Trè*_*rès 7

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

返回信息中的name,first_name,last_name,image,email:scope =>'userinfo.email,userinfo.profile'

您可以在此处查看提交