Class yii\authclient\OAuth2
OAuth2 serves as a client for the OAuth 2 flow.
In oder to acquire access token perform following sequence:
use yii\authclient\OAuth2;
$oauthClient = new OAuth2();
$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/.
Public Properties
Public Methods
Protected Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| CONTENT_TYPE_AUTO | 'auto' | yii\authclient\BaseOAuth | |
| CONTENT_TYPE_JSON | 'json' | yii\authclient\BaseOAuth | |
| CONTENT_TYPE_URLENCODED | 'urlencoded' | yii\authclient\BaseOAuth | |
| CONTENT_TYPE_XML | 'xml' | yii\authclient\BaseOAuth |
Property Details
OAuth client ID.
OAuth client secret.
Token request URL endpoint.
Protocol version.
Method Details
Performs request to the OAuth API.
| array apiInternal( $accessToken, $url, $method, array $params, array $headers ) | ||
| $accessToken | yii\authclient\OAuthToken | Actual access token. |
| $url | string | Absolute API URL. |
| $method | string | Request method. |
| $params | array | Request parameters. |
| $headers | array | Additional request headers. |
| return | array | API response. |
|---|---|---|
| throws | yii\base\Exception | on failure. |
Composes user authorization URL.
| string buildAuthUrl( array $params = [] ) | ||
| $params | array | Additional auth GET params. |
| return | string | Authorization URL. |
|---|---|---|
Composes HTTP request CUrl options, which will be merged with the default ones.
| array composeRequestCurlOptions( $method, $url, array $params ) | ||
| $method | string | Request type. |
| $url | string | Request URL. |
| $params | array | Request params. |
| return | array | CUrl options. |
|---|---|---|
| throws | yii\base\Exception | on failure. |
Creates token from its configuration.
| yii\authclient\OAuthToken createToken( array $tokenConfig = [] ) | ||
| $tokenConfig | array | Token configuration. |
| return | yii\authclient\OAuthToken | Token instance. |
|---|---|---|
Composes default $returnUrl value.
| string defaultReturnUrl( ) | ||
| return | string | Return URL. |
|---|---|---|
Fetches access token from authorization code.
| yii\authclient\OAuthToken fetchAccessToken( $authCode, array $params = [] ) | ||
| $authCode | string | Authorization code, usually comes at $_GET['code']. |
| $params | array | Additional request params. |
| return | yii\authclient\OAuthToken | Access token. |
|---|---|---|
Gets new auth token to replace expired one.
| yii\authclient\OAuthToken refreshAccessToken( \yii\authclient\OAuthToken $token ) | ||
| $token | yii\authclient\OAuthToken | Expired auth token. |
| return | yii\authclient\OAuthToken | New auth token. |
|---|---|---|