我正在使用 rails 插件 open_id_authentication在我的应用程序中。这适用于 MyOpenID,但是使用 Google 进行身份验证时,我无法将电子邮件地址作为必需属性的一部分。
据我了解,Google 会忽略 sreg 属性请求,并且只监听 AX 架构以获取电子邮件地址。
这是我的代码:
def open_id_authentication(openid_url)
#google only responds to AX for email, so we must provide that also
authenticate_with_open_id(openid_url, :required => [:nickname, :email, 'http://axschema.org/contact/email']) do |result, identity_url, registration|
if result.successful?
@user = User.find_or_initialize_by_identity_url(identity_url)
if @user.new_record?
unless registration['email'] || registration['http://axschema.org/contact/email']
failed_login "Your OpenID provider didn't send us an email address."
return
end
#some providers (like Google) won't send a nick name. We'll use email instead for those
nick = registration['nickname']
nick |= registration['email']
nick |= registration['http://axschema.org/contact/email']
email = registration['email'];
email |= registration['http://axschema.org/contact/email']
@user.login = nick
@user.email = email
@user.save(false)
end
self.current_user = @user
successful_login
else
failed_login result.message
end
end
我的理解是,我按要求提交了电子邮件地址(sreg 和 AX),我应该能够将它们从
registration
中拉出。与响应一起传递的实例。当我使用 Google 登录时,电子邮件地址被传回为“t”。
我是否错误地处理了这个问题?如何从 Google 获取用户的电子邮件地址?我是否必须跳过任何其他障碍才能支持雅虎?
最佳答案
我最终自己解决了这个问题。找到支持 AX 架构 URL 的官方文档并不容易。
这是我发现的:
Google 将仅使用 AX 架构回复电子邮件地址:http://schema.openid.net/contact/email
雅虎将使用这些 AX 模式回复别名和电子邮件:
http://axschema.org/namePerson/friendly
http://axschema.org/contact/email
所以我需要为电子邮件地址请求基本上所有已知的 AX 架构 URL,并希望提供商发送它。/耸肩
关于ruby-on-rails - 在 Rails 中从 Google/Yahoo 检索 OpenID AX 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1956522/