Ben*_*man 4 openid authentication ruby-on-rails
我在我的应用程序中使用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
Run Code Online (Sandbox Code Playgroud)
我的理解是,我提交的电子邮件地址(包括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
Run Code Online (Sandbox Code Playgroud)
所以我需要基本上请求电子邮件地址的所有已知AX架构URL,并希望提供商发送它./耸肩
| 归档时间: |
|
| 查看次数: |
4639 次 |
| 最近记录: |