PHP Class 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
See also: http://oauth.net/2/
See also: https://tools.ietf.org/html/rfc6749
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends BaseOAuth
Afficher le fichier Open project: yiisoft/yii2-authclient Class Usage Examples

Méthodes publiques

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
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.

Méthodes protégées

Méthode Description
createToken ( array $tokenConfig = [] ) : OAuthToken Creates token from its configuration.
defaultReturnUrl ( ) : string Composes default [[returnUrl]] value.
generateAuthState ( ) : string Generates the auth state value.

Method Details

applyAccessTokenToRequest() public méthode

public applyAccessTokenToRequest ( $request, $accessToken )

authenticateClient() public méthode

Authenticate OAuth client directly at the provider without third party (user) involved, using 'client_credentials' grant type.
See also: http://tools.ietf.org/html/rfc6749#section-4.4
public authenticateClient ( array $params = [] ) : OAuthToken
$params array additional request params.
Résultat OAuthToken access token.

authenticateUser() public méthode

Authenticates user directly by 'username/password' pair, using 'password' grant type.
See also: 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.
Résultat OAuthToken access token.

buildAuthUrl() public méthode

Composes user authorization URL.
public buildAuthUrl ( array $params = [] ) : string
$params array additional auth GET params.
Résultat string authorization URL.

createToken() protected méthode

Creates token from its configuration.
protected createToken ( array $tokenConfig = [] ) : OAuthToken
$tokenConfig array token configuration.
Résultat OAuthToken token instance.

defaultReturnUrl() protected méthode

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

fetchAccessToken() public méthode

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.
Résultat OAuthToken access token.

generateAuthState() protected méthode

Generates the auth state value.
Since: 2.1
protected generateAuthState ( ) : string
Résultat string auth state value.

refreshAccessToken() public méthode

Gets new auth token to replace expired one.
public refreshAccessToken ( OAuthToken $token ) : OAuthToken
$token OAuthToken expired auth token.
Résultat OAuthToken new auth token.

Property Details

$clientId public_oe property

OAuth client ID.
public $clientId

$clientSecret public_oe property

OAuth client secret.
public $clientSecret

$tokenUrl public_oe property

token request URL endpoint.
public $tokenUrl

$validateAuthState public_oe property

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.
Since: 2.1
public $validateAuthState

$version public_oe property

protocol version.
public $version