ruby-on-rails – 从Rails中的Google / Yahoo检索OpenID AX属性
发布时间:2020-12-17 03:51:08 所属栏目:百科 来源:网络整理
导读:我在我的应用程序中使用rails插件 open_id_authentication.这适用于MyOpenID,但是对Google进行身份验证我无法将电子邮件地址作为必需属性的一部分. 据我所知,Google忽略了sreg属性请求,只监听AX架构的电子邮件地址. 这是我的代码: def open_id_authenticati
我在我的应用程序中使用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),我应该能够将它们从与响应一起传递的注册实例中提取出来. 当我使用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,并希望提供商发送它. /耸肩 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |