/**
  * Authenticates the given OpenId identity.
  * Defined by Zend_Auth_Adapter_Interface.
  *
  * @throws Zend_Auth_Adapter_Exception If answering the authentication
  *                                     query is impossible
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $result = parent::authenticate();
     if ($result->isValid() && ($username = $this->extractUsername($result->getIdentity()))) {
         return new Zend_Auth_Result($result->getCode(), $username, $result->getMessages());
     }
     return $result;
 }
Example #2
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     if ($request->getPost('openid_identifier') || $request->getParam('openid_mode')) {
         $sreg = $this->getSreg();
         $openIdAdapter = new Zend_Auth_Adapter_OpenId($request->getPost('openid_identifier'), null, null, null, $sreg);
         $result = $openIdAdapter->authenticate();
         if ($result->isValid()) {
             return $this->_getUserData($result->getIdentity(), $sreg->getProperties());
         } else {
             $errors = $result->getMessages();
             array_walk($errors, array($this, '_addError'));
         }
     }
     $this->_addError('Insufficient data received');
     return false;
 }
Example #3
0
    public function testAuthenticateVerifyPostValid()
    {
        $expiresIn = time() + 600;
        $storage = new Zend_OpenId_Consumer_Storage_File();
        $storage->delDiscoveryInfo(self::ID);
        $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn);
        $storage->delAssociation(self::SERVER);
        $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn);
        $storage->purgeNonces();

        $_SERVER['REQUEST_METHOD'] = 'POST';
        $_GET = array();
        $_POST = array(
            "openid_return_to" => "http://www.zf-test.com/test.php",
            "openid_assoc_handle" => self::HANDLE,
            "openid_claimed_id" => self::ID,
            "openid_identity" => self::REAL_ID,
            "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe",
            "openid_mode" => "id_res",
            "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed",
            "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw="
        );
        $adapter = new Zend_Auth_Adapter_OpenId();
        $ret = $adapter->authenticate();
        $this->assertTrue($ret->isValid());
    }
Example #4
0
 function testSetHttpClient()
 {
     $storage = new Zend_OpenId_Consumer_Storage_File(dirname(__FILE__) . "/_files");
     $storage->delDiscoveryInfo(self::ID);
     $storage->delAssociation(self::SERVER);
     $adapter = new Zend_Auth_Adapter_OpenId(self::ID, $storage);
     $http = new Zend_Http_Client(null, array('maxredirects' => 4, 'timeout' => 15, 'useragent' => 'Zend_OpenId'));
     $test = new Zend_Http_Client_Adapter_Test();
     $http->setAdapter($test);
     $adapter->SetHttpClient($http);
     $ret = $adapter->authenticate();
     $this->assertSame("GET / HTTP/1.1\r\n" . "Host: id.myopenid.com\r\n" . "Connection: close\r\n" . "Accept-encoding: gzip, deflate\r\n" . "User-Agent: Zend_OpenId\r\n\r\n", $http->getLastRequest());
 }