PHP Класс yii\authclient\OAuth2

In oder to acquire access token perform following sequence: php use yii\authclient\OAuth2; assuming class MyAuthClient extends OAuth2 $oauthClient = new MyAuthClient(); $url = $oauthClient->buildAuthUrl(); // Build authorization URL Yii::$app->getResponse()->redirect($url); // Redirect to authorization URL. After user returns at our site: $code = $_GET['code']; $accessToken = $oauthClient->fetchAccessToken($code); // Get access token
См. также: http://oauth.net/2/
См. также: https://tools.ietf.org/html/rfc6749
С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends BaseOAuth
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$clientId OAuth client ID.
$clientSecret OAuth client secret.
$tokenUrl token request URL endpoint.
$validateAuthState whether to use and validate auth 'state' parameter in authentication flow. If enabled - the opaque value will be generated and applied to auth URL to maintain state between the request and callback. The authorization server includes this value, when redirecting the user-agent back to the client. The option is used for preventing cross-site request forgery.
$version protocol version.

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

Метод Описание
applyAccessTokenToRequest ( $request, $accessToken )
authenticateClient ( array $params = [] ) : OAuthToken Authenticate OAuth client directly at the provider without third party (user) involved, using 'client_credentials' grant type.
authenticateUser ( string $username, string $password, array $params = [] ) : OAuthToken Authenticates user directly by 'username/password' pair, using 'password' grant type.
buildAuthUrl ( array $params = [] ) : string Composes user authorization URL.
fetchAccessToken ( string $authCode, array $params = [] ) : OAuthToken Fetches access token from authorization code.
refreshAccessToken ( OAuthToken $token ) : OAuthToken Gets new auth token to replace expired one.

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

Метод Описание
createToken ( array $tokenConfig = [] ) : OAuthToken Creates token from its configuration.
defaultReturnUrl ( ) : string Composes default [[returnUrl]] value.
generateAuthState ( ) : string Generates the auth state value.

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

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

public applyAccessTokenToRequest ( $request, $accessToken )

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

Authenticate OAuth client directly at the provider without third party (user) involved, using 'client_credentials' grant type.
См. также: http://tools.ietf.org/html/rfc6749#section-4.4
public authenticateClient ( array $params = [] ) : OAuthToken
$params array additional request params.
Результат OAuthToken access token.

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

Authenticates user directly by 'username/password' pair, using 'password' grant type.
См. также: https://tools.ietf.org/html/rfc6749#section-4.3
public authenticateUser ( string $username, string $password, array $params = [] ) : OAuthToken
$username string user name.
$password string user password.
$params array additional request params.
Результат OAuthToken access token.

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

Composes user authorization URL.
public buildAuthUrl ( array $params = [] ) : string
$params array additional auth GET params.
Результат string authorization URL.

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

Creates token from its configuration.
protected createToken ( array $tokenConfig = [] ) : OAuthToken
$tokenConfig array token configuration.
Результат OAuthToken token instance.

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

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

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

Fetches access token from authorization code.
public fetchAccessToken ( string $authCode, array $params = [] ) : OAuthToken
$authCode string authorization code, usually comes at $_GET['code'].
$params array additional request params.
Результат OAuthToken access token.

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

Generates the auth state value.
С версии: 2.1
protected generateAuthState ( ) : string
Результат string auth state value.

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

Gets new auth token to replace expired one.
public refreshAccessToken ( OAuthToken $token ) : OAuthToken
$token OAuthToken expired auth token.
Результат OAuthToken new auth token.

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

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

OAuth client ID.
public $clientId

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

OAuth client secret.
public $clientSecret

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

token request URL endpoint.
public $tokenUrl

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

whether to use and validate auth 'state' parameter in authentication flow. If enabled - the opaque value will be generated and applied to auth URL to maintain state between the request and callback. The authorization server includes this value, when redirecting the user-agent back to the client. The option is used for preventing cross-site request forgery.
С версии: 2.1
public $validateAuthState

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

protocol version.
public $version