PHP Класс 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]].
См. также: http://openid.net/
С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends BaseClient, implements yii\authclient\ClientInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Описание методов

buildAuthUrl() публичный Метод

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.
Результат string the authentication URL.

buildAuthUrlV1() защищенный Метод

Builds authentication URL for the protocol version 1.
protected buildAuthUrlV1 ( array $serverInfo ) : string
$serverInfo array OpenID server info.
Результат string authentication URL.

buildAuthUrlV2() защищенный Метод

Builds authentication URL for the protocol version 2.
protected buildAuthUrlV2 ( array $serverInfo ) : string
$serverInfo array OpenID server info.
Результат string authentication URL.

buildAxParams() защищенный Метод

Composes AX request parameters.
protected buildAxParams ( ) : array
Результат array AX parameters.

buildSregParams() защищенный Метод

Composes SREG request parameters.
protected buildSregParams ( ) : array
Результат array SREG parameters.

buildUrl() защищенный Метод

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.
Результат string composed URL.

compareUrl() защищенный Метод

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.
Результат boolean whether URLs are equal.

defaultRequestOptions() защищенный Метод

protected defaultRequestOptions ( )

defaultReturnUrl() защищенный Метод

Generates default [[returnUrl]] value.
protected defaultReturnUrl ( ) : string
Результат string default authentication return URL.

discover() публичный Метод

Performs Yadis and HTML discovery.
public discover ( string $url ) : array
$url string Identity URL.
Результат 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() защищенный Метод

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.
Результат string | boolean searched value, "false" on failure.

fetchAttributes() публичный Метод

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.
См. также: http://www.axschema.org/types/
public fetchAttributes ( ) : array
Результат array array of attributes with keys being the AX schema names, e.g. 'contact/email'

fetchAxAttributes() защищенный Метод

Gets AX attributes provided by OP.
protected fetchAxAttributes ( ) : array
Результат array array of attributes.

fetchSregAttributes() защищенный Метод

Gets SREG attributes provided by OP. SREG names will be mapped to AX names.
protected fetchSregAttributes ( ) : array
Результат array array of attributes with keys being the AX schema names, e.g. 'contact/email'

getClaimedId() публичный Метод

public getClaimedId ( ) : string
Результат string claimed identifier (identity).

getReturnUrl() публичный Метод

public getReturnUrl ( ) : string
Результат string authentication return URL.

getTrustRoot() публичный Метод

public getTrustRoot ( ) : string
Результат string client trust root (realm).

hostExists() публичный Метод

Checks if the server specified in the url exists.
public hostExists ( string $url ) : boolean
$url string URL to check
Результат boolean true, if the server exists; false otherwise

init() публичный Метод

public init ( )

initUserAttributes() защищенный Метод

protected initUserAttributes ( )

sendRequest() защищенный Метод

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.
Результат array | string response.

setClaimedId() публичный Метод

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

setReturnUrl() публичный Метод

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

setTrustRoot() публичный Метод

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

validate() публичный Метод

Performs OpenID verification with the OP.
public validate ( boolean $validateRequiredAttributes = true ) : boolean
$validateRequiredAttributes boolean whether to validate required attributes.
Результат boolean whether the verification was successful.

validateRequiredAttributes() защищенный Метод

Checks if all required attributes are present in the server response.
protected validateRequiredAttributes ( ) : boolean
Результат boolean whether all required attributes are present.

Описание свойств

$authUrl публичное свойство

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

$axToSregMap публичное свойство

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

$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.
public $cainfo

$capath публичное свойство

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

$data публичное свойство

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

$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']
public $optionalAttributes

$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']
public $requiredAttributes

$verifyPeer публичное свойство

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