/** * 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)); }
require_once dirname(__FILE__) . '/Zend/OpenId/Extension/Ax.php'; $sreg = new Ak33m_OpenId_Extension_Ax(array('firstname' => true, 'email' => true, 'lastname' => true, 'dob' => true, 'gender' => true, 'postcode' => true, 'country' => true, 'language' => true, 'timezone' => true), null, 1.1); /* //echo file_get_contents('https://www.google.com/accounts/o8/id'); $openid_identifier = 'https://www.google.com/accounts/o8/id'; $status = ""; $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") {
/** * 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())); } } }