简体   繁体   English

使用Rails Omniauth gem和Google OpenID时,如何不要求用户发送电子邮件

[英]How do I NOT require user's email when using Rails Omniauth gem and Google OpenID

My current /config/initializers/omniauth.rb file contains: 我当前的/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

When I login via Google by going to /auth/google, Google reports: 当我通过访问/ auth / google登录Google时,Google会报告:

DOMAIN is asking for some information from your Google Account EMAIL - Email address: NAME (EMAIL) DOMAIN要求您提供来自Google帐户的一些信息EMAIL - 电子邮件地址: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: 对于Facebook,我发现我可以添加选项的“范围”属性,例如:

provider :facebook, 'APP_ID', 'APP_SECRET', {:scope => ''}

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. 基于对OpenID策略(Google Aps auth继承)的来源的快速回顾,您可以传入选项,指定哪些属性是可选的,而不是Attributes Exchange(AX)身份验证所需的属性。

See source code here for options: https://github.com/intridea/omniauth/blob/master/oa-openid/lib/omniauth/strategies/open_id.rb 有关选项,请参阅此处的源代码: 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. 我没有测试这个,只是阅读源代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户已经登录时,如何使用Twitter gem和Omniauth gem获取用户的访问令牌? - How do I fetch the access token for a user using the Twitter gem and the Omniauth gem when the users is already logged in? Rails:在Facebook Oauth之后获取用户的电子邮件(使用Devise和Facebook omniauth gem) - Rails: Get user's email after Facebook Oauth (using Devise & facebook omniauth gem) 如何确定Rails中正在使用哪个身份验证用户(OmniAuth) - How do I tell which authentication user is using in rails (OmniAuth) 如何使用Omniauth gem登录用户以进行我的Rails测试? - How can I login a user for my Rails tests using Omniauth gem? 如何使用linkedin gem和omniauth获得更精细的LinkedIn用户信息? - How do I get more granular LinkedIn user information using linkedin gem and omniauth? 在Rails中使用Omniauth时,如果该用户存在并使用其他身份验证,则Google_omniauth2会创建一个新用户 - When using Omniauth in Rails, Google_omniauth2 creates a new user if the user exists and use different auth Ruby和Rails与Omniauth-Google和OpenID错误 - Ruby and rails with Omniauth - google and openid error 我如何知道用户何时注册与在 Rails 中使用 Devise 和 Omniauth 登录 - How do I know when a user is registering vs logging in with Devise and Omniauth in Rails 在Rails 2.3.8和ruby 1.8.7中使用omniauth-google-oauth2 gem - Using omniauth-google-oauth2 gem in rails 2.3.8 and ruby 1.8.7 如何编写Rails 4测试以使用omniauth-google-oauth2 gem创建会话? - How can I write a Rails 4 test for creating a session with the omniauth-google-oauth2 gem?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM