在Rails中从Google / Yahoo检索OpenID AX属性

我在我的应用程序中使用rails插件open_id_authentication 。 这适用于MyOpenID,但是对Google进行身份validation我无法将电子邮件地址作为必需属性的一部分。

据我所知,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/emailhttp://schema.openid.net/contact/email

雅虎将使用这些AX模式回复别名和电子邮件:

 http://axschema.org/namePerson/friendly http://axschema.org/contact/email 

因此,我需要基本上请求所有已知的电子邮件地址的AX架构URL,并希望提供商发送它。 /耸肩

正如另一张海报已经提到的那样,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(" ") 

我不太了解你正在使用的Ruby OpenID库,但看起来你试图通过将其属性Type URI混合到Simple Registration扩展中来使用AX,这是一个非常不同的野兽。 您应该(因为我不清楚它)查看OpenID使用的文档或示例与您专门用于AX的库,并确保您遵循正确的步骤。 谷歌只支持AX,而雅虎支持简单注册(我不确定雅虎是否也支持AX)。

对我来说它仍然无法与http://schema.openid.net/contact/email但在此处找到https://groups.google.com/forum/?fromgroups=#!topic/google-federated-login -api / dOrQ8Ho5BGI它必须是openid.ax.required并且有效。