Source for file OpenID.php
Documentation is available at OpenID.php
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
require_once 'OpenID/Exception.php';
require_once 'HTTP/Request2.php';
require_once 'Validate.php';
require_once 'OpenID/Message.php';
require_once 'OpenID/Store.php';
* Base OpenID class. Contains common constants and helper static methods, as well
* as the directRequest() method, which handles direct communications. It also
* is a common place to assign your custom Storage class and Observers.
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
* @see OpenID_Observer_Common
* OP identifier constants
const NS_2_0 =
'http://specs.openid.net/auth/2.0';
const NS_1_1 =
'http://openid.net/signon/1.1';
const NS_2_0_ID_SELECT =
'http://specs.openid.net/auth/2.0/identifier_select';
const SERVICE_2_0_SERVER =
'http://specs.openid.net/auth/2.0/server';
const SERVICE_2_0_SIGNON =
'http://specs.openid.net/auth/2.0/signon';
const SERVICE_1_1_SIGNON =
'http://openid.net/signon/1.1';
const SERVICE_1_0_SIGNON =
'http://openid.net/signon/1.0';
* A map of which service types (versions) map to which protocol version. 1.0
* is mapped to 1.1. This is mostly helpful to see if openid.ns is supported.
self::SERVICE_2_0_SERVER =>
self::NS_2_0,
self::SERVICE_2_0_SIGNON =>
self::NS_2_0,
self::SERVICE_1_1_SIGNON =>
self::NS_1_1,
self::SERVICE_1_0_SIGNON =>
self::NS_1_1,
* Supported Association Hash Algorithms (preferred)
const HASH_ALGORITHM_2_0 =
'SHA256';
const HASH_ALGORITHM_1_1 =
'SHA1';
const MODE_ASSOCIATE =
'associate';
const MODE_CHECKID_SETUP =
'checkid_setup';
const MODE_CHECKID_IMMEDIATE =
'checkid_immediate';
const MODE_CHECK_AUTHENTICATION =
'check_authentication';
const MODE_ID_RES =
'id_res';
const MODE_CANCEL =
'cancel';
const MODE_SETUP_NEEDED =
'setup_needed';
const MODE_ERROR =
'error';
const SESSION_TYPE_NO_ENCRYPTION =
'no-encryption';
const SESSION_TYPE_DH_SHA1 =
'DH-SHA1';
const SESSION_TYPE_DH_SHA256 =
'DH-SHA256';
const ASSOC_TYPE_HMAC_SHA1 =
'HMAC-SHA1';
const ASSOC_TYPE_HMAC_SHA256 =
'HMAC-SHA256';
* Instance of OpenID_Store_Interface
static protected $store =
null;
* Array of attached observers
* @param OpenID_Observer_Common $observer Observer object
* @see OpenID_Observer_Log
static public function attach(OpenID_Observer_Common $observer)
foreach (self::$observers as $attached) {
if ($attached ===
$observer) {
self::$observers[] =
$observer;
* @param OpenID_Observer_Common $observer Observer object
static public function detach(OpenID_Observer_Common $observer)
foreach (self::$observers as $key =>
$attached) {
if ($attached ===
$observer) {
unset
(self::$observers[$key]);
* Notifies all observers of an event
static public function notify()
foreach (self::$observers as $observer) {
$observer->update(self::getLastEvent());
* Sets the last event and notifies the observers
* @param string $name Name of the event
* @param mixed $data The event's data
self::$lastEvent =
array(
* Sets a custom OpenID_Store_Interface object
* @param OpenID_Store_Interface $store Custom storage instance
static public function setStore(OpenID_Store_Interface $store)
* Gets the OpenID_Store_Interface instance. If none has been set, then the
* default store is used (CacheLite).
* @return OpenID_Store_Interface
if (!self::$store instanceof
OpenID_Store_Interface) {
self::$store =
OpenID_Store::factory();
* Sends a direct HTTP request.
* @param string $url URL to send the request to
* @param OpenID_Message $message Contains message contents
* @param array $options Options to pass to HTTP_Request2
* @see getHTTPRequest2Instance()
* @throws OpenID_Exception if send() fails
* @return HTTP_Request2_Response
array $options =
array())
$request->setConfig($options);
// Require POST, per the spec
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setBody($message->getHTTPFormat());
} catch
(HTTP_Request2_Exception $e) {
* Instantiates HTTP_Request2. Abstracted for testing.
* @return HTTP_Request2_Response
// @codeCoverageIgnoreStart
$request =
new HTTP_Request2();
$request->setAdapter('curl');
// @codeCoverageIgnoreEnd
* Returns an array of the 5 XRI globals symbols
return array('=', '@', '+', '$', '!');
* Normalizes an identifier (URI or XRI)
* @param mixed $identifier URI or XRI to be normalized
* @throws OpenID_Exception on invalid identifier
* @return string Normalized Identifier.
if (in_array($identifier[0], self::getXRIGlobalSymbols())) {
if (!preg_match('@^http[s]?://@i', $identifier)) {
$identifier =
'http://' .
$identifier;
if (Validate::uri($identifier)) {
Documentation generated on Tue, 15 Dec 2009 19:00:56 -0800 by phpDocumentor 1.4.3