使用 Zend_Auth 和 OpenID 获取 SREG 数据
我不知道如何在使用 Zend_Auth_Adapter_OpenId 时获取 SREG 扩展值。我正在关注这些文档页面:
http://framework.zend.com/manual/en/zend.auth .introduction.html
http://framework.zend.com/manual/en/zend.openid .consumer.html
在 Zend_Auth 的文档中,它说当使用 OpenID 进行第二次调用authenticate() 时,如下所示:
$auth_result = $auth->authenticate(new Zend_Auth_Adapter_OpenId());
这有效,$auth_result 最终为 Zend_Auth_Result::SUCCESS。
然而,在 Zend_OpenId_Consumer 文档中,为了获取返回的 SREG 数据,它说要这样做:
$sreg = new Zend_OpenId_Extension_Sreg(array('email'=>false,'fullname'=>false), null, 1.1);
$consumer = new Zend_OpenId_Consumer();
$consumer->verify($_GET, $id, $sreg);
这也有效,因为 verify() 返回 true 并且 $sreg->getProperties() 返回我请求的 SREG 字段。
问题是这两件事我都做不到!如果我首先调用authenticate(),则verify()返回false。如果我先 verify(),则authenticate() 返回 Zend_Auth_Result::FAILURE。查看 Zend/Auth/Adapter/OpenId.php 中的代码,很明显,authenticate() 正在内部调用 verify(),这是有道理的。但是,此内部调用填充的 SREG 值不会通过我所看到的任何方式公开。我缺少什么?
(在输入此内容并进行实验时,我发现我可以从 $_GET 中获取 SREG 值,例如 $_GET['openid_sreg_email'],但这似乎不是预期的模式。它解决了我的问题,但是我还是想知道是否有更官方的解决方案。)
I can't figure out how to get SREG extension values when using Zend_Auth_Adapter_OpenId. I'm following these documentation pages:
http://framework.zend.com/manual/en/zend.auth.introduction.html
http://framework.zend.com/manual/en/zend.openid.consumer.html
In the documentation on Zend_Auth, it says when using OpenID to make a second call to authenticate(), like this:
$auth_result = $auth->authenticate(new Zend_Auth_Adapter_OpenId());
And that works, with $auth_result ending up as Zend_Auth_Result::SUCCESS.
However, in the Zend_OpenId_Consumer documentation, in order to get at the returned SREG data it says to do this:
$sreg = new Zend_OpenId_Extension_Sreg(array('email'=>false,'fullname'=>false), null, 1.1);
$consumer = new Zend_OpenId_Consumer();
$consumer->verify($_GET, $id, $sreg);
And that works too, as verify() returns true and $sreg->getProperties() returns the SREG fields I requested.
The problem is that I cannot do both of these things! If I make that call to authenticate() first, then verify() returns false. If I verify() first, then authenticate() returns Zend_Auth_Result::FAILURE. Looking at the code in Zend/Auth/Adapter/OpenId.php, it's evident that authenticate() is calling verify() internally, which makes sense. However the SREG values that are populated by this internal call are not exposed through any means I can see. What am I missing?
(While typing this and experimenting I discovered that I can just grab the SREG values off of $_GET, e.g. $_GET['openid_sreg_email'], but that doesn't seem like it would be the intended pattern. It solves my problem, but I would still like to know if there is a more official solution.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Zend 官方不支持 OpenID 2.0 和 Google OpenID 提供程序。但问题跟踪器提供了一个补丁。这是该补丁的链接。您必须从该站点替换您的 Consumer.php。应用此补丁后,OpenID 应该可以与 Google 和其他主要提供商(例如 Yahoo!)合作。
说到OP,从OpenID结果获取SREG,GET参数没有这样的标准。这已经在 StackOverflow 此处和中讨论过一次Meta StackOverflow 此处。
属性交换 是 Zend Framework 中需要的另一件事。
相关问题此处。
Zend officially does not support OpenID 2.0 and Google OpenID provider. But there is a patch available from the Issue tracker. Here is the link to that patch. You must replace your Consumer.php from that site. After applying this patch, OpenID should work with Google and other major providers like Yahoo!
And talking about the OP, getting SREG from OpenID result, there is no such standard available for the GET parameter. This is already discussed once in StackOverflow here and in Meta StackOverflow here.
Attribute Exchange is another thing that is needed in Zend Framework.
Related question here.