我在我的应用中使用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)都提交为 required ,我应该能够将它们从与registration
实例一起传递出来响应。
当我使用Google登录时,电子邮件地址将作为“t”传回。
我处理不正确吗?如何从Google获取用户的电子邮件地址?我是否必须通过其他任何环节来支持雅虎?
答案 0 :(得分:7)
我最终自己解决了这个问题。找到支持AX架构URL的官方文档并不容易。
这是我发现的:
Google将仅使用AX架构回复电子邮件地址:http://schema.openid.net/contact/email
雅虎将回应别名&使用这些AX架构发送电子邮件:
http://axschema.org/namePerson/friendly
http://axschema.org/contact/email
所以我需要基本上请求电子邮件地址的所有已知AX架构URL,并希望提供商发送它。 /耸肩
答案 1 :(得分:2)
正如另一张海报已经提到的那样,Google现在会响应AX架构的电子邮件。我知道这篇文章是在不久前写的,但谷歌仍然没有回复namePerson。但是,它们提供了:
http://axschema.org/namePerson/first
http://axschema.org/namePerson/last
因此,要回答Shripad K的上述问题,您可以使用上面的代码作为示例:
name = [
registration['http://axschema.org/namePerson/first'],
registration['http://axschema.org/namePerson/last']
].join(" ")
答案 2 :(得分:1)
我不知道你正在使用的Ruby OpenID库,但看起来你试图通过将其属性Type URI混合到Simple Registration扩展中来使用AX,这是一个非常不同的野兽。您应该(因为我不清楚它)查看OpenID使用的文档或示例与您专门用于AX的库,并确保您遵循正确的步骤。谷歌只支持AX,而雅虎支持简单注册(我不确定雅虎是否也支持AX)。
答案 3 :(得分:0)
对我来说,它仍然无法与http://schema.openid.net/contact/email
一起使用,但在https://groups.google.com/forum/?fromgroups=#!topic/google-federated-login-api/dOrQ8Ho5BGI发现它必须 openid.ax.required 并且有效。