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 学不会递归,理解不了汉诺塔参数变化
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)