Class yii\authclient\OAuth2

Inheritanceyii\authclient\OAuth2 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\Object
Implementsyii\authclient\ClientInterface, yii\base\Configurable
Subclassesyii\authclient\clients\Facebook, yii\authclient\clients\GitHub, yii\authclient\clients\GoogleHybrid, yii\authclient\clients\GoogleOAuth, yii\authclient\clients\LinkedIn, yii\authclient\clients\Live, yii\authclient\clients\VKontakte, yii\authclient\clients\YandexOAuth
Available since version2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/OAuth2.php

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 Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
api() Performs request to the OAuth API. yii\authclient\BaseOAuth
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
buildAuthUrl() Composes user authorization URL. yii\authclient\OAuth2
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\Object
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
fetchAccessToken() Fetches access token from authorization code. yii\authclient\OAuth2
getAccessToken() yii\authclient\BaseOAuth
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getCurlOptions() yii\authclient\BaseOAuth
getId() yii\authclient\ClientInterface
getName() yii\authclient\ClientInterface
getNormalizeUserAttributeMap() yii\authclient\BaseClient
getReturnUrl() yii\authclient\BaseOAuth
getSignatureMethod() yii\authclient\BaseOAuth
getTitle() yii\authclient\ClientInterface
getUserAttributes() yii\authclient\ClientInterface
getViewOptions() yii\authclient\ClientInterface
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. yii\base\Object
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
refreshAccessToken() Gets new auth token to replace expired one. yii\authclient\OAuth2
setAccessToken() yii\authclient\BaseOAuth
setCurlOptions() yii\authclient\BaseOAuth
setId() yii\authclient\ClientInterface
setName() yii\authclient\ClientInterface
setNormalizeUserAttributeMap() yii\authclient\BaseClient
setReturnUrl() yii\authclient\BaseOAuth
setSignatureMethod() yii\authclient\BaseOAuth
setTitle() yii\authclient\ClientInterface
setUserAttributes() yii\authclient\BaseClient
setViewOptions() yii\authclient\BaseClient
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
apiInternal() Performs request to the OAuth API. yii\authclient\OAuth2
composeRequestCurlOptions() Composes HTTP request CUrl options, which will be merged with the default ones. yii\authclient\OAuth2
composeUrl() Composes URL from base URL and GET params. yii\authclient\BaseOAuth
convertXmlToArray() Converts XML document to array. yii\authclient\BaseOAuth
createSignatureMethod() Creates signature method instance from its configuration. yii\authclient\BaseOAuth
createToken() Creates token from its configuration. yii\authclient\OAuth2
defaultCurlOptions() Returns default cURL options. yii\authclient\BaseOAuth
defaultName() Generates service name. yii\authclient\BaseClient
defaultNormalizeUserAttributeMap() Returns the default $normalizeUserAttributeMap value. yii\authclient\BaseClient
defaultReturnUrl() Composes default $returnUrl value. yii\authclient\OAuth2
defaultTitle() Generates service title. yii\authclient\BaseClient
defaultViewOptions() Returns the default $viewOptions value. yii\authclient\BaseClient
determineContentTypeByHeaders() Attempts to determine HTTP request content type by headers. yii\authclient\BaseOAuth
determineContentTypeByRaw() Attempts to determine the content type from raw content. yii\authclient\BaseOAuth
getState() Returns persistent state value. yii\authclient\BaseOAuth
getStateKeyPrefix() Returns session key prefix, which is used to store internal states. yii\authclient\BaseOAuth
initUserAttributes() Initializes authenticated user attributes. yii\authclient\BaseClient
mergeCurlOptions() Merge CUrl options. yii\authclient\BaseOAuth
normalizeUserAttributes() Normalize given user attributes according to $normalizeUserAttributeMap. yii\authclient\BaseClient
processResponse() Processes raw response converting it to actual data. yii\authclient\BaseOAuth
removeState() Removes persistent state value. yii\authclient\BaseOAuth
restoreAccessToken() Restores access token. yii\authclient\BaseOAuth
saveAccessToken() Saves token as persistent state. yii\authclient\BaseOAuth
sendRequest() Sends HTTP request. yii\authclient\BaseOAuth
setState() Sets persistent state. yii\authclient\BaseOAuth

Constants

Hide inherited constants

ConstantValueDescriptionDefined 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

$clientId public property

OAuth client ID.

$clientSecret public property

OAuth client secret.

$tokenUrl public property

Token request URL endpoint.

$version public property
string $version '2.0'

Protocol version.

Method Details

apiInternal() protected method

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.

buildAuthUrl() public method

Composes user authorization URL.

string buildAuthUrl( array $params = [] )
$params array

Additional auth GET params.

return string

Authorization URL.

composeRequestCurlOptions() protected method

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.

createToken() protected method

Creates token from its configuration.

yii\authclient\OAuthToken createToken( array $tokenConfig = [] )
$tokenConfig array

Token configuration.

return yii\authclient\OAuthToken

Token instance.

defaultReturnUrl() protected method

Composes default $returnUrl value.

string defaultReturnUrl( )
return string

Return URL.

fetchAccessToken() public method

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.

refreshAccessToken() public method

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.