class (none) \ LightOpenID


This class provides a simple interface for OpenID (1.1 and 2.0) authentication. Supports Yadis discovery. The authentication process is stateless/dumb.

Usage: Sign-on with OpenID is a two step process: Step one is authentication with the provider: $openid = new LightOpenID('my-host.example.org'); $openid->identity = 'ID supplied by user'; header('Location: ' . $openid->authUrl()); The provider then sends various parameters via GET, one of them is openid_mode. Step two is verification: $openid = new LightOpenID('my-host.example.org'); if ($openid->mode) { echo $openid->validate() ? 'Logged in.' : 'Failed'; }

Change the 'my-host.example.org' to your domain name. Do NOT use $_SERVER['HTTP_HOST'] for that, unless you know what you are doing.

Optionally, you can set $returnUrl and $realm (or $trustRoot, which is an alias). The default values for those are: $openid->realm = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; $openid->returnUrl = $openid->realm . $_SERVER['REQUEST_URI']; If you don't know their meaning, refer to any openid tutorial, or specification. Or just guess.

AX and SREG extensions are supported. To use them, specify $openid->required and/or $openid->optional before calling $openid->authUrl(). These are arrays, with values being AX schema paths (the 'path' part of the URL). For example: $openid->required = array('namePerson/friendly', 'contact/email'); $openid->optional = array('namePerson/first'); If the server supports only SREG or OpenID 1.1, these are automaticaly mapped to SREG names, so that user doesn't have to know anything about the server.

To get the values, use $openid->getAttributes().

If LIGHTOPENID_TIMEOUT is defined, then this value (in ms) will be used to timeout the CURL OpenID requests; by default, this is limited to 10 seconds (instead of infinite). This can help in blocking potential Denial of Service attacks.

The library requires PHP >= 5.1.2 with curl or http/https stream wrappers enabled.


Method Summary

Name Description
__construct($host)
__get($name)
__set($name, $value)
authUrl($immediate = false) Returns authentication url. Usually, you want to redirect your user to it.
authUrl_v1($immediate)
authUrl_v2($immediate)
axParams()
build_url($url, $parts)
discover($url) Performs Yadis and HTML discovery. Normally not used.
getAttributes() Gets AX/SREG attributes provided by OP. should be used only after successful validaton. Note that it does not guarantee that any of the required/optional parameters will be present, or that there will be no other attributes besides those specified. In other words. OP may provide whatever information it wants to. * SREG names will be mapped to AX names. * @return Array Array of attributes with keys being the AX schema names, e.g. 'contact/email'
getAxAttributes()
getSregAttributes()
hostExists($url) Checks if the server specified in the url exists.
htmlTag($content, $tag, $attrName, $attrValue, $valueName) Helper function used to scan for / tags and extract information from them
parse_header_array($array, $update_claimed_id)
request($url, $method = "GET", $params = array(), $update_claimed_id = false)
request_curl($url, $method = "GET", $params = array(), $update_claimed_id)
request_streams($url, $method = "GET", $params = array(), $update_claimed_id)
sregParams()
validate() Performs OpenID verification with the OP.

public function __construct($host)


public function __get($name)


public function __set($name, $value)


public function authUrl($immediate = false)

Returns authentication url. Usually, you want to redirect your user to it.

Parameters:
String - $select_identifier Whether to request OP to select identity for an user in OpenID 2. Does not affect OpenID 1.
Defaults:
immediate = false
Returns:
String The authentication url.
Throws:
ErrorException

protected function authUrl_v1($immediate)


protected function authUrl_v2($immediate)


protected function axParams()


protected function build_url($url, $parts)


public function discover($url)

Performs Yadis and HTML discovery. Normally not used.

Parameters:
$url - Identity URL.
Returns:
String OP Endpoint (i.e. OpenID provider address).
Throws:
ErrorException

public function getAttributes()

Gets AX/SREG attributes provided by OP. should be used only after successful validaton. Note that it does not guarantee that any of the required/optional parameters will be present, or that there will be no other attributes besides those specified. In other words. OP may provide whatever information it wants to. * SREG names will be mapped to AX names. * @return Array Array of attributes with keys being the AX schema names, e.g. 'contact/email'

See:
http://www.axschema.org/types/

protected function getAxAttributes()


protected function getSregAttributes()


public function hostExists($url)

Checks if the server specified in the url exists.

Parameters:
$url - url to check
Returns:
true, if the server exists; false otherwise

protected function htmlTag($content, $tag, $attrName, $attrValue, $valueName)

Helper function used to scan for / tags and extract information from them


protected function parse_header_array($array, $update_claimed_id)


protected function request($url, $method = "GET", $params = array(), $update_claimed_id = false)

Defaults:
method = "GET"
params = array()
update_claimed_id = false

protected function request_curl($url, $method = "GET", $params = array(), $update_claimed_id)

Defaults:
method = "GET"
params = array()

protected function request_streams($url, $method = "GET", $params = array(), $update_claimed_id)

Defaults:
method = "GET"
params = array()

protected function sregParams()


public function validate()

Performs OpenID verification with the OP.

Returns:
Bool Whether the verification was successful.
Throws:
ErrorException