Skip to content

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: if ($this->data['openid_mode']) { $openid = new LightOpenID('my-host.example.org'); 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().

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

  • Full name: \LightOpenID

Properties

returnUrl

public $returnUrl

required

public $required

optional

public $optional

verify_peer

public $verify_peer

capath

public $capath

cainfo

public $cainfo

data

public $data

identity

private $identity

claimed_id

private $claimed_id

server

protected $server

version

protected $version

trustRoot

protected $trustRoot

aliases

protected $aliases

identifier_select

protected $identifier_select

ax

protected $ax

sreg

protected $sreg

setup_url

protected $setup_url

ax_to_sreg

protected static $ax_to_sreg
  • This property is static.

Methods

__construct

public __construct(mixed $host): mixed

Parameters:

Parameter Type Description
$host mixed

__set

public __set(mixed $name, mixed $value): mixed

Parameters:

Parameter Type Description
$name mixed
$value mixed

__get

public __get(mixed $name): mixed

Parameters:

Parameter Type Description
$name mixed

hostExists

Checks if the server specified in the url exists.

public hostExists(mixed $url): mixed

Parameters:

Parameter Type Description
$url mixed url to check

request_curl

protected request_curl(mixed $url, mixed $method = 'GET', mixed $params = array()): mixed

Parameters:

Parameter Type Description
$url mixed
$method mixed
$params mixed

request_streams

protected request_streams(mixed $url, mixed $method = 'GET', mixed $params = array()): mixed

Parameters:

Parameter Type Description
$url mixed
$method mixed
$params mixed

request

protected request(mixed $url, mixed $method = 'GET', mixed $params = array()): mixed

Parameters:

Parameter Type Description
$url mixed
$method mixed
$params mixed

build_url

protected build_url(mixed $url, mixed $parts): mixed

Parameters:

Parameter Type Description
$url mixed
$parts mixed

htmlTag

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

protected htmlTag(mixed $content, mixed $tag, mixed $attrName, mixed $attrValue, mixed $valueName): mixed

Parameters:

Parameter Type Description
$content mixed
$tag mixed
$attrName mixed
$attrValue mixed
$valueName mixed

discover

Performs Yadis and HTML discovery. Normally not used.

public discover(mixed $url): string

Parameters:

Parameter Type Description
$url mixed Identity URL.

Return Value:

OP Endpoint (i.e. OpenID provider address).

Throws:


sregParams

protected sregParams(): mixed

axParams

protected axParams(): mixed

authUrl_v1

protected authUrl_v1(mixed $immediate): mixed

Parameters:

Parameter Type Description
$immediate mixed

authUrl_v2

protected authUrl_v2(mixed $immediate): mixed

Parameters:

Parameter Type Description
$immediate mixed

authUrl

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

public authUrl(mixed $immediate = false): string

Parameters:

Parameter Type Description
$immediate mixed

Return Value:

The authentication url.

Throws:


validate

Performs OpenID verification with the OP.

public validate(): bool

Return Value:

Whether the verification was successful.

Throws:


getAxAttributes

protected getAxAttributes(): mixed

getSregAttributes

protected getSregAttributes(): mixed

getAttributes

Gets AX/SREG attributes provided by OP. should be used only after successful validaton.

public getAttributes(): mixed

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 Also:

  • http://www.axschema.org/types/ -


Automatically generated on 2025-03-18