dqunzip3183 2010-07-28 15:43
浏览 21
已采纳

Zend Framework OpenID消费者

I am using the Zend_OpenId_Consumer to provide OpenID access, the login is working fine, but when I call verify() I am recieving the error

`Wrong openid.return_to 'http://[host]/user/openid' != 'http://[host]/user/openid?[OpenIdResponse]

The issue as far as I can see is that the verify method is comparing the URL without the query part to the entire URL which includes all of the OpenID response information. It gets this url from Zend_OpenId::selfUrl()

I'm using the verify code from the doc pages

$consumer = new Zend_OpenId_Consumer();

if($this->_request->getParam('openid_mode')) {

    $id = $this->_request->getParam('openid_claimed_id');

    if($this->_request->getParam('openid_mode') == 'id_res') {

        if($consumer->verify($this->_request->getParams(),$id)) {
            $status = 'VALID ' . $id;
        }
        else {
               $status = 'INVALID ' . $id;
        }

    }
    elseif($this->_request->getParam('openid_mode') == 'cancel') {
       $status = 'CANCELLED';
    }
}

Am I doing something wrong here?

  • 写回答

1条回答 默认 最新

  • douxiong2738 2010-08-03 14:57
    关注

    perhaps this is helpful

    Integration with Zend_Controller

    Finally a couple of words about integration into Model-View-Controller applications: such Zend Framework applications are implemented using the Zend_Controller class and they use objects of the Zend_Controller_Response_Http class to prepare HTTP responses and send them back to the user's web browser. Zend_OpenId_Consumer doesn't provide any GUI capabilities but it performs HTTP redirections on success of Zend_OpenId_Consumer::login and Zend_OpenId_Consumer::check. These redirections may work incorrectly or not at all if some data was already sent to the web browser. To properly perform HTTP redirection in MVC code the real Zend_Controller_Response_Http should be sent to Zend_OpenId_Consumer::login or Zend_OpenId_Consumer::check as the last argument.

    zend.openid.consumer

    strange, i've just tested OpenId_Consumer on my localserver with ZF 1.10.3... no problem at all

    my Action

       public function openidAction() {
          $this->view->status = "";
          if ($this->getRequest()->isPost()) {
             $consumer = new Zend_OpenId_Consumer();
             if (!$consumer->login($this->getRequest()->getParam('openid_identifier'))) {
                $this->view->status = "OpenID login failed.";
             }
          } else if ($this->getRequest()->getParam('openid_mode')) {
             if ($this->getRequest()->getParam('openid_mode') == "id_res") {
                $consumer = new Zend_OpenId_Consumer();
                if ($consumer->verify($this->getRequest()->getParams(), $id)) {
                   $this->view->status = "VALID " . htmlspecialchars($id);
                } else {
                   $this->view->status = "INVALID " . htmlspecialchars($id);
                }
             } else if ($_GET['openid_mode'] == "cancel") {
                $this->view->status = "CANCELLED";
             }
          }
       }
    

    my View

    <p><?php echo "{$this->status}" ?></p>
    <form method="post">
       <fieldset>
          <legend>OpenID Login</legend>
          <input type="text" name="openid_identifier" value=""/>
          <input type="submit" name="openid_action" value="login"/>
       </fieldset>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog