PHP Class yii\authclient\OpenId

Supports Yadis and HTML discovery. Usage: ~~~ use yii\authclient\OpenId; $client = new OpenId(); $client->authUrl = 'https://open.id.provider.url'; // Setup provider endpoint $url = $client->buildAuthUrl(); // Get authentication URL return Yii::$app->getResponse()->redirect($url); // Redirect to authentication URL After user returns at our site: if ($client->validate()) { // validate response $userAttributes = $client->getUserAttributes(); // get account info ... } ~~~ AX and SREG extensions are supported. To use them, specify [[requiredAttributes]] and/or [[optionalAttributes]].
See also: http://openid.net/
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends BaseClient, implements yii\authclient\ClientInterface
Afficher le fichier Open project: yiisoft/yii2-authclient Class Usage Examples

Méthodes publiques

Свойство Type Description
$authUrl authentication base URL, which should be used to compose actual authentication URL by OpenId::buildAuthUrl method.
$axToSregMap map of matches between AX and SREG attribute names in format: axAttributeName => sregAttributeName
$cainfo the name of a file holding one or more certificates to verify the peer with. This value will take effect only if [[verifyPeer]] is set.
$capath directory that holds multiple CA certificates. This value will take effect only if [[verifyPeer]] is set.
$data data, which should be used to retrieve the OpenID response. If not set combination of GET and POST will be used.
$optionalAttributes list of attributes, which could be returned from server. Attribute names should be always specified in AX format. For example: php ['namePerson/first', 'namePerson/last']
$requiredAttributes list of attributes, which always should be returned from server. Attribute names should be always specified in AX format. For example: php ['namePerson/friendly', 'contact/email']
$verifyPeer whether to verify the peer's certificate.

Méthodes publiques

Méthode Description
buildAuthUrl ( boolean $identifierSelect = null ) : string Returns authentication URL. Usually, you want to redirect your user to it.
discover ( string $url ) : array Performs Yadis and HTML discovery.
fetchAttributes ( ) : array Gets AX/SREG attributes provided by OP. Should be used only after successful validation.
getClaimedId ( ) : string
getReturnUrl ( ) : string
getTrustRoot ( ) : string
hostExists ( string $url ) : boolean Checks if the server specified in the url exists.
init ( )
setClaimedId ( string $claimedId )
setReturnUrl ( string $returnUrl )
setTrustRoot ( string $value )
validate ( boolean $validateRequiredAttributes = true ) : boolean Performs OpenID verification with the OP.

Méthodes protégées

Méthode Description
buildAuthUrlV1 ( array $serverInfo ) : string Builds authentication URL for the protocol version 1.
buildAuthUrlV2 ( array $serverInfo ) : string Builds authentication URL for the protocol version 2.
buildAxParams ( ) : array Composes AX request parameters.
buildSregParams ( ) : array Composes SREG request parameters.
buildUrl ( string $baseUrl, string | array $additionalUrl ) : string Combines given URLs into single one.
compareUrl ( string $expectedUrl, string $actualUrl ) : boolean Compares 2 URLs taking in account possible GET parameters order miss match and URL encoding inconsistencies.
defaultRequestOptions ( )
defaultReturnUrl ( ) : string Generates default [[returnUrl]] value.
extractHtmlTagValue ( string $content, string $tag, string $matchAttributeName, string $matchAttributeValue, string $valueAttributeName ) : string | boolean Scans content for / tags and extract information from them.
fetchAxAttributes ( ) : array Gets AX attributes provided by OP.
fetchSregAttributes ( ) : array Gets SREG attributes provided by OP. SREG names will be mapped to AX names.
initUserAttributes ( )
sendRequest ( string $url, string $method = 'GET', array $params = [] ) : array | string Sends request to the server
validateRequiredAttributes ( ) : boolean Checks if all required attributes are present in the server response.

Method Details

buildAuthUrl() public méthode

Returns authentication URL. Usually, you want to redirect your user to it.
public buildAuthUrl ( boolean $identifierSelect = null ) : string
$identifierSelect boolean whether to request OP to select identity for an user in OpenID 2, does not affect OpenID 1.
Résultat string the authentication URL.

buildAuthUrlV1() protected méthode

Builds authentication URL for the protocol version 1.
protected buildAuthUrlV1 ( array $serverInfo ) : string
$serverInfo array OpenID server info.
Résultat string authentication URL.

buildAuthUrlV2() protected méthode

Builds authentication URL for the protocol version 2.
protected buildAuthUrlV2 ( array $serverInfo ) : string
$serverInfo array OpenID server info.
Résultat string authentication URL.

buildAxParams() protected méthode

Composes AX request parameters.
protected buildAxParams ( ) : array
Résultat array AX parameters.

buildSregParams() protected méthode

Composes SREG request parameters.
protected buildSregParams ( ) : array
Résultat array SREG parameters.

buildUrl() protected méthode

Combines given URLs into single one.
protected buildUrl ( string $baseUrl, string | array $additionalUrl ) : string
$baseUrl string base URL.
$additionalUrl string | array additional URL string or information array.
Résultat string composed URL.

compareUrl() protected méthode

Compares 2 URLs taking in account possible GET parameters order miss match and URL encoding inconsistencies.
protected compareUrl ( string $expectedUrl, string $actualUrl ) : boolean
$expectedUrl string expected URL.
$actualUrl string actual URL.
Résultat boolean whether URLs are equal.

defaultRequestOptions() protected méthode

protected defaultRequestOptions ( )

defaultReturnUrl() protected méthode

Generates default [[returnUrl]] value.
protected defaultReturnUrl ( ) : string
Résultat string default authentication return URL.

discover() public méthode

Performs Yadis and HTML discovery.
public discover ( string $url ) : array
$url string Identity URL.
Résultat array OpenID provider info, following keys will be available: - url: string, OP Endpoint (i.e. OpenID provider address). - version: int, OpenID protocol version used by provider. - identity: string, identity value. - identifier_select: bool, whether to request OP to select identity for an user in OpenID 2, does not affect OpenID 1. - ax: bool, whether AX attributes should be used. - sreg: bool, whether SREG attributes should be used.

extractHtmlTagValue() protected méthode

Scans content for / tags and extract information from them.
protected extractHtmlTagValue ( string $content, string $tag, string $matchAttributeName, string $matchAttributeValue, string $valueAttributeName ) : string | boolean
$content string HTML content to be be parsed.
$tag string name of the source tag.
$matchAttributeName string name of the source tag attribute, which should contain $matchAttributeValue
$matchAttributeValue string required value of $matchAttributeName
$valueAttributeName string name of the source tag attribute, which should contain searched value.
Résultat string | boolean searched value, "false" on failure.

fetchAttributes() public méthode

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.
See also: http://www.axschema.org/types/
public fetchAttributes ( ) : array
Résultat array array of attributes with keys being the AX schema names, e.g. 'contact/email'

fetchAxAttributes() protected méthode

Gets AX attributes provided by OP.
protected fetchAxAttributes ( ) : array
Résultat array array of attributes.

fetchSregAttributes() protected méthode

Gets SREG attributes provided by OP. SREG names will be mapped to AX names.
protected fetchSregAttributes ( ) : array
Résultat array array of attributes with keys being the AX schema names, e.g. 'contact/email'

getClaimedId() public méthode

public getClaimedId ( ) : string
Résultat string claimed identifier (identity).

getReturnUrl() public méthode

public getReturnUrl ( ) : string
Résultat string authentication return URL.

getTrustRoot() public méthode

public getTrustRoot ( ) : string
Résultat string client trust root (realm).

hostExists() public méthode

Checks if the server specified in the url exists.
public hostExists ( string $url ) : boolean
$url string URL to check
Résultat boolean true, if the server exists; false otherwise

init() public méthode

public init ( )

initUserAttributes() protected méthode

protected initUserAttributes ( )

sendRequest() protected méthode

Sends request to the server
protected sendRequest ( string $url, string $method = 'GET', array $params = [] ) : array | string
$url string request URL.
$method string request method.
$params array request parameters.
Résultat array | string response.

setClaimedId() public méthode

public setClaimedId ( string $claimedId )
$claimedId string claimed identifier (identity).

setReturnUrl() public méthode

public setReturnUrl ( string $returnUrl )
$returnUrl string authentication return URL.

setTrustRoot() public méthode

public setTrustRoot ( string $value )
$value string client trust root (realm).

validate() public méthode

Performs OpenID verification with the OP.
public validate ( boolean $validateRequiredAttributes = true ) : boolean
$validateRequiredAttributes boolean whether to validate required attributes.
Résultat boolean whether the verification was successful.

validateRequiredAttributes() protected méthode

Checks if all required attributes are present in the server response.
protected validateRequiredAttributes ( ) : boolean
Résultat boolean whether all required attributes are present.

Property Details

$authUrl public_oe property

authentication base URL, which should be used to compose actual authentication URL by OpenId::buildAuthUrl method.
public $authUrl

$axToSregMap public_oe property

map of matches between AX and SREG attribute names in format: axAttributeName => sregAttributeName
public $axToSregMap

$cainfo public_oe property

the name of a file holding one or more certificates to verify the peer with. This value will take effect only if [[verifyPeer]] is set.
public $cainfo

$capath public_oe property

directory that holds multiple CA certificates. This value will take effect only if [[verifyPeer]] is set.
public $capath

$data public_oe property

data, which should be used to retrieve the OpenID response. If not set combination of GET and POST will be used.
public $data

$optionalAttributes public_oe property

list of attributes, which could be returned from server. Attribute names should be always specified in AX format. For example: php ['namePerson/first', 'namePerson/last']
public $optionalAttributes

$requiredAttributes public_oe property

list of attributes, which always should be returned from server. Attribute names should be always specified in AX format. For example: php ['namePerson/friendly', 'contact/email']
public $requiredAttributes

$verifyPeer public_oe property

whether to verify the peer's certificate.
public $verifyPeer