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
required
optional
verify_peer
capath
cainfo
data
identity
claimed_id
server
version
trustRoot
aliases
identifier_select
ax
sreg
setup_url
ax_to_sreg
- This property is static.
Methods
__construct
Parameters:
Parameter | Type | Description |
---|---|---|
$host |
mixed |
__set
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
mixed | |
$value |
mixed |
__get
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
mixed |
hostExists
Checks if the server specified in the url exists.
Parameters:
Parameter | Type | Description |
---|---|---|
$url |
mixed | url to check |
request_curl
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
Parameters:
Parameter | Type | Description |
---|---|---|
$url |
mixed | |
$method |
mixed | |
$params |
mixed |
build_url
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.
Parameters:
Parameter | Type | Description |
---|---|---|
$url |
mixed | Identity URL. |
Return Value:
OP Endpoint (i.e. OpenID provider address).
Throws:
sregParams
axParams
authUrl_v1
Parameters:
Parameter | Type | Description |
---|---|---|
$immediate |
mixed |
authUrl_v2
Parameters:
Parameter | Type | Description |
---|---|---|
$immediate |
mixed |
authUrl
Returns authentication url. Usually, you want to redirect your user to it.
Parameters:
Parameter | Type | Description |
---|---|---|
$immediate |
mixed |
Return Value:
The authentication url.
Throws:
validate
Performs OpenID verification with the OP.
Return Value:
Whether the verification was successful.
Throws:
getAxAttributes
getSregAttributes
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 Also:
- http://www.axschema.org/types/ -
Automatically generated on 2025-03-18