使用 Rails Omniauth gem 和 Google OpenID 时如何不需要用户的电子邮件

发布于 2024-10-17 16:29:00 字数 559 浏览 3 评论 0原文

我当前的 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二货你真萌 2024-10-24 16:29:00

根据对 OpenID 策略(Google Aps 身份验证继承自)的源的快速审查,您可以传入选项,指定哪些属性是属性交换 (AX) 身份验证的可选属性和必需属性。

请参阅此处的源代码以获取选项:https: //github.com/intridea/omniauth/blob/master/oa-openid/lib/omniauth/strategies/open_id.rb

基于此,我认为您可以更改这样的选项以根据需要删除电子邮件属性:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :open_id, nil, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id', :required => [], :optional => []
end

祝你好运。我没有测试这个,只是阅读源码。

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:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :open_id, nil, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id', :required => [], :optional => []
end

Good luck. I didn't test this, just reading the source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文