- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在玩 authlogic-example-app当我注册用户时,我无法从 OpenID 提供商(在我的例子中是:Google 和 Yahoo)获得电子邮件地址。我得到一个空的响应而不是电子邮件地址(检查下面代码中的评论)。
这就是我的用户模型的样子(其他一切看起来都像上面提到的 authlogic-example-app 的“with_openid”分支)。除了丢失的“电子邮件”之外,openid-authentication-process 按预期工作:
class User < ActiveRecord::Base
acts_as_authentic do |c|
# not needed because I use OpenID
c.validate_login_field = false
# avoid failed validation before OpenID request
c.validate_email_field = false
# this one sets 'openid.sreg.required=email'
c.required_fields = [:email]
end
private
# overwriting the existing method in '/lib/authlogic_openid/acts_as_authentic.rb'
def map_openid_registration(registration)
# this is my problem: 'registration' is an empty hash
self.email ||= registration[:email] if respond_to?(:email) && !registration[:email].blank?
end
end
知道如何解决这个问题吗?这里有人在使用 authlogic 之前做过这个吗? ?或者更好:您有一个可行的示例吗?
更新:我检查了Google Account Authentication API并对比了authlogic提交的请求(使用 ruby-openid-gem 和 openid-authentication-plugin )与 example requests在 Google 帐户身份验证 API 文档中:
Google 验证和获取电子邮件地址的示例请求:
https://www.google.com/accounts/o8/ud
?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.return_to=http%3A%2F%2Fwww.example.com%2Fcheckauth
&openid.realm=http%3A%2F%2Fwww.example.com%2F
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup
&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ext1.mode=fetch_request
&openid.ext1.type.email=http%3A%2F%2Faxschema.org%2Fcontact%2Femail
&openid.ext1.required=email
我的应用程序提交的请求:
https://www.google.com/accounts/o8/ud
?openid.assoc_handle=AOQobUcdICerEyK6SXJfukaz8ygXiBqF_gKXv68OBtPXmeafBSdZ6576
&openid.ax.mode=fetch_request
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.mode=checkid_setup
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1
&openid.realm=http%3A%2F%2Flocalhost%3A3000%2F
&openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Faccount%3Ffor_model%3D1%26_method%3Dpost%26open_id_complete%3D1
&openid.sreg.required=email
在调试整个设置时,我发现 openid-authentication-plugin从 openid 提供商那里收到的响应中从未收到过电子邮件,这至少解释了为什么我的用户模型中的 registration
哈希为空...
更新:如果您正在使用 authlogic 和 openid,请不要忘记查看 latest railscast on this subject !
最佳答案
因为没有人能帮助我,所以我帮助了自己。 :-)
我的问题的简短回答是:
c.required_fields = [:email,"http://axschema.org/contact/email"]
使用此行,应用程序使用 sreg 和 ax(Google 支持的请求类型)请求电子邮件地址。
您可以通过 Javascript OpenID-Selector 找到更详细的答案和 authlogic-openid 的有效实现。就在这里:
http://github.com/vazqujav/authlogic_openid_selector_example/
关于ruby-on-rails - Ruby-OpenID:需要来自 OpenID 提供商的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/787894/
我在前几天的测验中遇到了以下问题。 Consider the code fragment (assumed to be in a program in which all variables are
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我刚开始接触 Objective-C,一般来说是 C,所以我想这也是一个 C 问题。它更像是一个为什么的问题,而不是一个如何做的问题问题。 我注意到,在除以两个整数时,小数部分向下舍入为 0,即使结果
我是一名优秀的程序员,十分优秀!