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
显示文件 Open project: yiisoft/yii2-authclient Class Usage Examples

Public Properties

Property 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.

Public Methods

Method 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.

Protected Methods

Method 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 method

public applyAccessTokenToRequest ( $request, $accessToken )

authenticateClient() public method

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.
return OAuthToken access token.

authenticateUser() public method

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.
return OAuthToken access token.

buildAuthUrl() public method

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

createToken() protected method

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

defaultReturnUrl() protected method

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

fetchAccessToken() public method

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.
return OAuthToken access token.

generateAuthState() protected method

Generates the auth state value.
Since: 2.1
protected generateAuthState ( ) : string
return string auth state value.

refreshAccessToken() public method

Gets new auth token to replace expired one.
public refreshAccessToken ( OAuthToken $token ) : OAuthToken
$token OAuthToken expired auth token.
return 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