Esempio n. 1
0
 /**
  * Authenticate user by google OpenId
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $config = $this->getConfig();
     if (empty($config['id'])) {
         require_once 'Zend/Auth/Adapter/Exception.php';
         throw new Zend_Auth_Adapter_Exception('Invalid google OpenId url');
     }
     $consumer = new Ak33m_OpenId_Consumer();
     $googleExt = new SAuth_Provider_Google_Extension();
     if (is_array($config['exchangeExtension']) && !empty($config['exchangeExtension'])) {
         $googleExt->setParams($config['exchangeExtension']);
     }
     if (!isset($_GET['openid_mode']) || empty($_GET['openid_mode'])) {
         $consumer->login($config['id'], $config['callbackUrl'], $config['root'], $googleExt);
         if ($error = $consumer->getError()) {
             return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, false, array($error));
         }
     } elseif (isset($_GET['openid_mode']) && $_GET['openid_mode'] == 'id_res') {
         if ($consumer->verify($_GET, $id, $googleExt)) {
             $identity = $this->_prepareIdentity($_GET);
             return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
         }
     }
     $error = 'Google openId verification has been faild';
     return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, false, array($error));
 }
Esempio n. 2
0
 /**
  * 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()
 {
     $id = $this->_id;
     if (!empty($id)) {
         $consumer = new Ak33m_OpenId_Consumer($this->_storage);
         $consumer->setHttpClient($this->_httpClient);
         /* login() is never returns on success */
         if (!$this->_check_immediate) {
             if (!$consumer->login($id, $this->_returnTo, $this->_root, $this->_extensions, $this->_response)) {
                 return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $id, array("Authentication failed", $consumer->getError()));
             }
         } else {
             if (!$consumer->check($id, $this->_returnTo, $this->_root, $this->_extensions, $this->_response)) {
                 return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $id, array("Authentication failed", $consumer->getError()));
             }
         }
     } else {
         $params = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET;
         $consumer = new Ak33m_OpenId_Consumer($this->_storage);
         $consumer->setHttpClient($this->_httpClient);
         if ($consumer->verify($params, $id, $this->_extensions)) {
             return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id, array("Authentication successful"));
         } else {
             return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $id, array("Authentication failed", $consumer->getError()));
         }
     }
 }