# Abstract Class yii\authclient\BaseOAuth

Inheritance | yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\BaseObject
Implements | yii\authclient\ClientInterface, yii\base\Configurable

Subclasses

yii\authclient\OAuth1, yii\authclient\OAuth2, yii\authclient\OpenIdConnect, yii\authclient\clients\Facebook, yii\authclient\clients\GitHub, yii\authclient\clients\Google, yii\authclient\clients\GoogleHybrid, yii\authclient\clients\LinkedIn, yii\authclient\clients\Live, yii\authclient\clients\Twitter, yii\authclient\clients\TwitterOAuth2, yii\authclient\clients\VKontakte, yii\authclient\clients\Yandex

Available since version | 2.0
Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/BaseOAuth.php

BaseOAuth is a base class for the OAuth clients.

See also http://oauth.net/.

## Public Properties

Hide inherited properties

Property | Type | Description | Defined By
--- | --- | --- | ---
$accessToken | yii\authclient\OAuthToken | Auth token instance. Note that the type of this property differs in getter and setter. See getAccessToken() and setAccessToken() for details. | yii\authclient\BaseOAuth
$apiBaseUrl | string | API base URL. | yii\authclient\BaseOAuth
$authUrl | string | Authorize URL. | yii\authclient\BaseOAuth
$autoRefreshAccessToken | boolean | Whether to automatically perform 'refresh access token' request on expired access token. | yii\authclient\BaseOAuth
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. This property is read-only. | yii\base\Component
$httpClient | yii\httpclient\Client | Internal HTTP client. Note that the type of this property differs in getter and setter. See getHttpClient() and setHttpClient() for details. | yii\authclient\BaseClient
$id | string | Service id. | yii\authclient\BaseClient
$name | string | Service name. | yii\authclient\BaseClient
$normalizeUserAttributeMap | array | Normalize user attribute map. | yii\authclient\BaseClient
$parametersToKeepInReturnUrl | array | List of the parameters to keep in default return url. | yii\authclient\BaseOAuth
$requestOptions | array | HTTP request options. This property is read-only. | yii\authclient\BaseClient
$returnUrl | string | Return URL. | yii\authclient\BaseOAuth
$scope | string | Auth request scope. | yii\authclient\BaseOAuth
$signatureMethod | yii\authclient\signature\BaseMethod | Signature method instance. Note that the type of this property differs in getter and setter. See getSignatureMethod() and setSignatureMethod() for details. | yii\authclient\BaseOAuth
$stateStorage | yii\authclient\StateStorageInterface | Stage storage. Note that the type of this property differs in getter and setter. See getStateStorage() and setStateStorage() for details. | yii\authclient\BaseClient
$title | string | Service title. | yii\authclient\BaseClient
$userAttributes | array | List of user attributes. | yii\authclient\BaseClient
$version | string | Protocol version. | yii\authclient\BaseOAuth
$viewOptions | array | View options in format: optionName => optionValue. | yii\authclient\BaseClient

## Public Methods

Hide inherited methods

Method | Description | Defined 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\BaseObject
__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 returning response data. | yii\authclient\BaseOAuth
applyAccessTokenToRequest() | Applies access token to the HTTP request instance. | 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
beforeApiRequestSend() | Handles yii\httpclient\Request::EVENT_BEFORE_SEND event. | yii\authclient\BaseOAuth
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component
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\BaseObject
createApiRequest() | Creates an HTTP request for the API call. | yii\authclient\BaseOAuth
createRequest() | Creates HTTP request instance. | yii\authclient\BaseClient
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
getAccessToken() |  | yii\authclient\BaseOAuth
getBehavior() | Returns the named behavior object. | yii\base\Component
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component
getHttpClient() | Returns HTTP client. | yii\authclient\BaseClient
getId() |  | yii\authclient\ClientInterface
getName() |  | yii\authclient\ClientInterface
getNormalizeUserAttributeMap() |  | yii\authclient\BaseClient
getRequestOptions() |  | yii\authclient\BaseClient
getReturnUrl() |  | yii\authclient\BaseOAuth
getSignatureMethod() |  | yii\authclient\BaseOAuth
getStateStorage() |  | yii\authclient\BaseClient
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\BaseObject
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\BaseOAuth
setAccessToken() | Sets access token to be used. | yii\authclient\BaseOAuth
setHttpClient() | Sets HTTP client to be used. | yii\authclient\BaseOAuth
setId() |  | yii\authclient\ClientInterface
setName() |  | yii\authclient\ClientInterface
setNormalizeUserAttributeMap() |  | yii\authclient\BaseClient
setRequestOptions() |  | yii\authclient\BaseClient
setReturnUrl() |  | yii\authclient\BaseOAuth
setSignatureMethod() | Set signature method to be used. | yii\authclient\BaseOAuth
setStateStorage() |  | yii\authclient\BaseClient
setTitle() |  | yii\authclient\ClientInterface
setUserAttributes() |  | yii\authclient\BaseClient
setViewOptions() |  | yii\authclient\BaseClient
trigger() | Triggers an event. | yii\base\Component

## Protected Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
composeUrl() | Composes URL from base URL and GET params. | yii\authclient\BaseOAuth
createHttpClient() | Creates HTTP client instance from reference or configuration. | yii\authclient\BaseOAuth
createSignatureMethod() | Creates signature method instance from its configuration. | yii\authclient\BaseOAuth
createToken() | Creates token from its configuration. | yii\authclient\BaseOAuth
defaultName() | Generates service name. | yii\authclient\BaseClient
defaultNormalizeUserAttributeMap() | Returns the default $normalizeUserAttributeMap value. | yii\authclient\BaseClient
defaultRequestOptions() | Returns default HTTP request options. | yii\authclient\BaseOAuth
defaultReturnUrl() | Composes default $returnUrl value. | yii\authclient\BaseOAuth
defaultTitle() | Generates service title. | yii\authclient\BaseClient
defaultViewOptions() | Returns the default $viewOptions value. | yii\authclient\BaseClient
getState() | Returns persistent state value. | yii\authclient\BaseClient
getStateKeyPrefix() | Returns session key prefix, which is used to store internal states. | yii\authclient\BaseClient
initUserAttributes() | Initializes authenticated user attributes. | yii\authclient\BaseClient
normalizeUserAttributes() | Normalize given user attributes according to $normalizeUserAttributeMap. | yii\authclient\BaseClient
removeState() | Removes persistent state value. | yii\authclient\BaseClient
restoreAccessToken() | Restores access token. | yii\authclient\BaseOAuth
saveAccessToken() | Saves token as persistent state. | yii\authclient\BaseOAuth
sendRequest() | Sends the given HTTP request, returning response data. | yii\authclient\BaseOAuth
setState() | Sets persistent state. | yii\authclient\BaseClient

## Property Details

$accessToken public property

Auth token instance. Note that the type of this property differs in getter and setter. See getAccessToken() and setAccessToken() for details.

public yii\authclient\OAuthToken $accessToken = null
$apiBaseUrl public property

API base URL. This field will be used as yii\httpclient\Client::$baseUrl value of $httpClient. Note: changing this property will take no effect after $httpClient is instantiated.

public string $apiBaseUrl = null
$authUrl public property

Authorize URL.

public string $authUrl = null
$autoRefreshAccessToken public property (available since version 2.0.6)

Whether to automatically perform 'refresh access token' request on expired access token.

public boolean $autoRefreshAccessToken = true
$parametersToKeepInReturnUrl public property (available since version 2.2.4)

List of the parameters to keep in default return url.

public array $parametersToKeepInReturnUrl = ['authclient']
$returnUrl public property

Return URL.

public string $returnUrl = null
$scope public property

Auth request scope.

public string $scope = null
$signatureMethod public property

Signature method instance. Note that the type of this property differs in getter and setter. See getSignatureMethod() and setSignatureMethod() for details.

public yii\authclient\signature\BaseMethod $signatureMethod = null
$version public property

Protocol version.

public string $version = '1.0'

## Method Details

api() public method

Performs request to the OAuth API returning response data.

You may use createApiRequest() method instead, gaining more control over request execution.

See also createApiRequest().

public array api ( $apiSubUrl, $method = 'GET', $data = [], $headers = [] )
$apiSubUrl | string | API sub URL, which will be append to $apiBaseUrl, or absolute API URL.
$method | string | Request method.
$data | array|string | Request data or content.
$headers | array | Additional request headers.
return | array | API response data.

applyAccessTokenToRequest() public abstract method (available since version 2.1)

Applies access token to the HTTP request instance.

public abstract void applyAccessTokenToRequest ( $request, $accessToken )
$request | yii\httpclient\Request | HTTP request instance.
$accessToken | yii\authclient\OAuthToken | Access token instance.

beforeApiRequestSend() public method (available since version 2.1)

Handles yii\httpclient\Request::EVENT_BEFORE_SEND event.

Applies $accessToken to the request.

public void beforeApiRequestSend ( $event )
$event | yii\httpclient\RequestEvent | Event instance.
throws | yii\base\Exception | on invalid access token.

composeUrl() protected method

Composes URL from base URL and GET params.

protected string composeUrl ( $url, array $params = [] )
$url | string | Base URL.
$params | array | GET params.
return | string | Composed URL.

createApiRequest() public method (available since version 2.1)

Creates an HTTP request for the API call.

The created request will be automatically processed adding access token parameters and signature before sending. You may use createRequest() to gain full control over request composition and execution.

See also createRequest().

public yii\httpclient\Request createApiRequest ( )
return | yii\httpclient\Request | HTTP request instance.

createHttpClient() protected method (available since version 2.1)

Creates HTTP client instance from reference or configuration.

protected yii\httpclient\Client createHttpClient ( $reference )
$reference | string|array | Component name or array configuration.
return | yii\httpclient\Client | HTTP client instance.

createSignatureMethod() protected method

Creates signature method instance from its configuration.

protected yii\authclient\signature\BaseMethod createSignatureMethod ( array $signatureMethodConfig )
$signatureMethodConfig | array | Signature method configuration.
return | yii\authclient\signature\BaseMethod | Signature method instance.

createToken() protected method

Creates token from its configuration.

protected yii\authclient\OAuthToken createToken ( array $tokenConfig = [] )
$tokenConfig | array | Token configuration.
return | yii\authclient\OAuthToken | Token instance.

defaultRequestOptions() protected method (available since version 2.1)

Returns default HTTP request options.

protected array defaultRequestOptions ( )
return | array | HTTP request options.

defaultReturnUrl() protected method

Composes default $returnUrl value.

protected string defaultReturnUrl ( )
return | string | Return URL.

getAccessToken() public method

public yii\authclient\OAuthToken getAccessToken ( )
return | yii\authclient\OAuthToken | Auth token instance.

getReturnUrl() public method

public string getReturnUrl ( )
return | string | Return URL.

getSignatureMethod() public method

public yii\authclient\signature\BaseMethod getSignatureMethod ( )
return | yii\authclient\signature\BaseMethod | Signature method instance.

refreshAccessToken() public abstract method

Gets new auth token to replace expired one.

public abstract yii\authclient\OAuthToken refreshAccessToken ( yii\authclient\OAuthToken $token )
$token | yii\authclient\OAuthToken | Expired auth token.
return | yii\authclient\OAuthToken | New auth token.

restoreAccessToken() protected method

Restores access token.

protected yii\authclient\OAuthToken restoreAccessToken ( )
return | yii\authclient\OAuthToken | Auth token.

saveAccessToken() protected method

Saves token as persistent state.

protected $this saveAccessToken ( $token )
$token | yii\authclient\OAuthToken|null | Auth token to be saved.
return | $this | The object itself.

sendRequest() protected method (available since version 2.1)

Sends the given HTTP request, returning response data.

protected array sendRequest ( $request )
$request | yii\httpclient\Request | HTTP request to be sent.
return | array | Response data.
throws | yii\authclient\InvalidResponseException | on invalid remote response.

setAccessToken() public method

Sets access token to be used.

public void setAccessToken ( $token )
$token | array|yii\authclient\OAuthToken|null | Access token or its configuration. Set to null to restore token from token store.

setHttpClient() public method (available since version 2.1)

Sets HTTP client to be used.

public void setHttpClient ( $httpClient )
$httpClient | array|yii\httpclient\Client | Internal HTTP client.

setReturnUrl() public method

public void setReturnUrl ( $returnUrl )
$returnUrl | string | Return URL

setSignatureMethod() public method

Set signature method to be used.

public void setSignatureMethod ( $signatureMethod )
$signatureMethod | array|yii\authclient\signature\BaseMethod | Signature method instance or its array configuration.
throws | yii\base\InvalidArgumentException | on wrong argument.