/** * Constructs a Zend\OpenId\Provider\GenericProvider object with given parameters. * * @param string $loginUrl is an URL that provides login screen for * end-user (by default it is the same URL with additional GET variable * openid.action=login) * @param string $trustUrl is an URL that shows a question if end-user * trust to given consumer (by default it is the same URL with additional * GET variable openid.action=trust) * @param Zend\OpenId\Provider\User\AbstractUser $user is an object for communication * with User-Agent and store information about logged-in user (it is a * Zend\OpenId\Provider\User\Session object by default) * @param Zend\OpenId\Provider\Storage $storage is an object for keeping * persistent database (it is a Zend\OpenId\Provider\Storage_File object * by default) * @param integer $sessionTtl is a default time to live for association * session in seconds (1 hour by default). Consumer must reestablish * association after that time. */ public function __construct($loginUrl = null, $trustUrl = null, User\AbstractUser $user = null, Storage\AbstractStorage $storage = null, $sessionTtl = 3600) { if ($loginUrl === null) { $loginUrl = OpenId\OpenId::selfUrl() . '?openid.action=login'; } else { $loginUrl = OpenId\OpenId::absoluteUrl($loginUrl); } $this->_loginUrl = $loginUrl; if ($trustUrl === null) { $trustUrl = OpenId\OpenId::selfUrl() . '?openid.action=trust'; } else { $trustUrl = OpenId\OpenId::absoluteUrl($trustUrl); } $this->_trustUrl = $trustUrl; if ($user === null) { $this->_user = new User\Session(); } else { $this->_user = $user; } if ($storage === null) { $this->_storage = new Storage\File(); } else { $this->_storage = $storage; } $this->_sessionTtl = $sessionTtl; }
/** * testing testAbsolutefUrl * */ public function testAbsoluteUrl() { unset($_SERVER['SCRIPT_URI']); unset($_SERVER['HTTPS']); unset($_SERVER['HTTP_HOST']); unset($_SERVER['SERVER_NAME']); unset($_SERVER['SERVER_PORT']); unset($_SERVER['SCRIPT_URL']); unset($_SERVER['REDIRECT_URL']); unset($_SERVER['PHP_SELF']); unset($_SERVER['SCRIPT_NAME']); unset($_SERVER['PATH_INFO']); $_SERVER['HTTP_HOST'] = "www.test.com"; $_SERVER['SCRIPT_NAME'] = '/a/b/c/test.php'; $this->assertSame( 'http://www.test.com/a/b/c/test.php', OpenId::absoluteUrl("") ); $this->assertSame( 'http://www.test.com/a/b/c/ok.php', OpenId::absoluteUrl("ok.php") ); $this->assertSame( 'http://www.test.com/a/ok.php', OpenId::absoluteUrl("/a/ok.php") ); $this->assertSame( 'http://www.php.net/ok.php', OpenId::absoluteUrl("http://www.php.net/ok.php") ); $this->assertSame( 'https://www.php.net/ok.php', OpenId::absoluteUrl("https://www.php.net/ok.php") ); $_SERVER['SCRIPT_NAME'] = '/test.php'; $this->assertSame( 'http://www.test.com/a/b.php', OpenId::absoluteUrl("/a/b.php") ); $this->assertSame( 'http://www.test.com/a/b.php', OpenId::absoluteUrl("a/b.php") ); }
/** * Performs check of OpenID identity. * * This is the first step of OpenID authentication process. * On success the function does not return (it does HTTP redirection to * server and exits). On failure it returns false. * * @param bool $immediate enables or disables interaction with user * @param string $id OpenID identity * @param string $returnTo HTTP URL to redirect response from server to * @param string $root HTTP URL to identify consumer on server * @param mixed $extensions extension object or array of extensions objects * @param Zend\Controller\Response\AbstractResponse $response an optional response * object to perform HTTP or HTML form redirection * @return bool */ protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Response\AbstractResponse $response = null) { $this->_setError(''); if (!OpenId\OpenId::normalize($id)) { $this->_setError("Normalisation failed"); return false; } $claimedId = $id; if (!$this->_discovery($id, $server, $version)) { $this->_setError("Discovery failed: " . $this->getError()); return false; } if (!$this->_associate($server, $version)) { $this->_setError("Association failed: " . $this->getError()); return false; } if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) { /* Use dumb mode */ unset($handle); unset($macFunc); unset($secret); unset($expires); } $params = array(); if ($version >= 2.0) { $params['openid.ns'] = OpenId\OpenId::NS_2_0; } $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup'; $params['openid.identity'] = $id; $params['openid.claimed_id'] = $claimedId; if ($version <= 2.0) { if ($this->_session !== null) { $this->_session->identity = $id; $this->_session->claimed_id = $claimedId; } else { if (defined('SID')) { $_SESSION["zend_openid"] = array("identity" => $id, "claimed_id" => $claimedId); } else { $this->_session = new \Zend\Session\Container("zend_openid"); $this->_session->identity = $id; $this->_session->claimed_id = $claimedId; } } } if (isset($handle)) { $params['openid.assoc_handle'] = $handle; } $params['openid.return_to'] = OpenId\OpenId::absoluteUrl($returnTo); if (empty($root)) { $root = OpenId\OpenId::selfUrl(); if ($root[strlen($root) - 1] != '/') { $root = dirname($root); } } if ($version >= 2.0) { $params['openid.realm'] = $root; } else { $params['openid.trust_root'] = $root; } if (!Extension\AbstractExtension::forAll($extensions, 'prepareRequest', $params)) { $this->_setError("Extension::prepareRequest failure"); return false; } OpenId\OpenId::redirect($server, $params, $response); return true; }