使用 Rails Omniauth gem 和 Google OpenID 时如何不需要用户的电子邮件
我当前的 /config/initializers/omniauth.rb 文件包含:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :open_id, nil, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end
当我通过 Google 登录 /auth/google 时,Google 报告:
DOMAIN 正在要求您提供 Google 帐户电子邮件中的一些信息 - 电子邮件地址:姓名(电子邮件)
我的应用程序不需要用户的电子邮件,因此我想消除此进入障碍。有没有办法取消这个要求。对于 Facebook,我发现我可以添加选项的“范围”属性,例如:
provider :facebook, 'APP_ID', 'APP_SECRET', {:scope => ''}
My current /config/initializers/omniauth.rb file contains:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :open_id, nil, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end
When I login via Google by going to /auth/google, Google reports:
DOMAIN is asking for some information from your Google Account EMAIL
- Email address: NAME (EMAIL)
My application doesn't need the user's email and so I'd like to remove this barrier to entry. Is there anyway to remove this requirement. For Facebook, I've found I can add the "scope" property of options, for example:
provider :facebook, 'APP_ID', 'APP_SECRET', {:scope => ''}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据对 OpenID 策略(Google Aps 身份验证继承自)的源的快速审查,您可以传入选项,指定哪些属性是属性交换 (AX) 身份验证的可选属性和必需属性。
请参阅此处的源代码以获取选项:https: //github.com/intridea/omniauth/blob/master/oa-openid/lib/omniauth/strategies/open_id.rb
基于此,我认为您可以更改这样的选项以根据需要删除电子邮件属性:
祝你好运。我没有测试这个,只是阅读源码。
Based on a quick review of the source for the OpenID strategy (which Google Aps auth inherits from), you can pass in options specifying which attributes are optional vs. required for an Attributes Exchange (AX) auth.
See source code here for options: https://github.com/intridea/omniauth/blob/master/oa-openid/lib/omniauth/strategies/open_id.rb
Based on that, I think you could change the options like so to remove email as a required attribute:
Good luck. I didn't test this, just reading the source.