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));
 }
$consumer = new Zend_OpenId_Consumer();
 if (!$consumer->login($openid_identifier, 'google_openid_return.php', null , $sreg)) {
   //echo $consumer->getError();
   $status = "OpenID login failed.";
 }
*/
$status = "";
if (isset($_POST['openid_action']) && $_POST['openid_action'] == "login" && !empty($_POST['openid_identifier'])) {
    $consumer = new Ak33m_OpenId_Consumer();
    if (!$consumer->login($_POST['openid_identifier'], 'google_federated_login.php', null, $sreg)) {
        $status = "OpenID login failed.";
    }
} else {
    if (isset($_GET['openid_mode'])) {
        if ($_GET['openid_mode'] == "id_res") {
            $consumer = new Ak33m_OpenId_Consumer();
            if ($consumer->verify($_GET, $id, $sreg)) {
                $status = "VALID " . htmlspecialchars($id);
                $data = $sreg->getProperties();
                print_r($data);
            } else {
                $status = "INVALID " . htmlspecialchars($id);
            }
        } else {
            if ($_GET['openid_mode'] == "cancel") {
                $status = "CANCELLED";
            }
        }
    }
}
?>
Esempio n. 3
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()));
         }
     }
 }
            } else {
                $data = $sreg->getProperties();
                $_SESSION["google"]["openid_identity"] = $google_openid_identity;
                $_SESSION["google"]["firstname"] = $data["firstname"];
                $_SESSION["google"]["lastname"] = $data["lastname"];
                $_SESSION["google"]["email"] = $data["email"];
                $_SESSION["google"]["lang"] = $data["en"];
                header('Location: user_glogin.php?message=Welcome to Ofuz Google login. You do not seem to have an Ofuz account linked to your google login.');
                exit;
            }
        } else {
            //$status = "INVALID " . htmlspecialchars($id);
            header('Location: user_login.php?message=Sorry! Google has identified your login as INVALID. Please try with VALID login.');
            exit;
        }
    } else {
        if ($_GET['openid_mode'] == "cancel") {
            //$status = "CANCELLED";
            header('Location: user_login.php?message=You have cancelled login with your Google Account.');
            exit;
        }
    }
} else {
    $openid_identifier = 'https://www.google.com/accounts/o8/id';
    $consumer = new Ak33m_OpenId_Consumer();
    if (!$consumer->login($openid_identifier, 'google_federated_login.php', null, $sreg)) {
        //$status = "OpenID login failed.";
        header('Location: user_login.php?message=Sorry! Login with your Google Account has failed. Please try again.');
        exit;
    }
}