views:

149

answers:

1

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  A: 

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>
maggie
Thanks for this, no luck sadly. I have just tried passing the response object into the login method but the issue still seems to be in the verify method.
Neil Aitken
Thanks for the edit, what version of PHP are you running?
Neil Aitken
PHP 5.3.2 and ZF 1.10.3
maggie
I'm only using 5.2.5 with 1.10.3. I dont see it making a difference but that maybe the problem.I'm getting the same with your action and form, there must be something amiss in my local environment. I'll try it on another machine.
Neil Aitken