Class yii\authclient\clients\Twitter

Inheritanceyii\authclient\clients\Twitter » yii\authclient\OAuth1 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\BaseObject
Implementsyii\authclient\ClientInterface, yii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/clients/Twitter.php

Twitter allows authentication via Twitter OAuth.

In order to use Twitter OAuth you must register your application at https://dev.twitter.com/apps/new.

Example application configuration:

'components' => [
    'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'twitter' => [
                'class' => 'yii\authclient\clients\Twitter',
                'attributeParams' => [
                    'include_email' => 'true'
                ],
                'consumerKey' => 'twitter_consumer_key',
                'consumerSecret' => 'twitter_consumer_secret',
            ],
        ],
    ]
    // ...
]

Note: some auth workflows provided by Twitter, such as application-only authentication, uses OAuth 2 protocol and thus are impossible to be used with this class. You should use yii\authclient\clients\TwitterOAuth2 for these.

See also:

Public Properties

Hide inherited properties

Property Type Description Defined By
$accessToken yii\authclient\OAuthToken Auth token instance. yii\authclient\BaseOAuth
$accessTokenMethod string Access token HTTP method. yii\authclient\clients\Twitter
$accessTokenUrl string OAuth access token URL. yii\authclient\clients\Twitter
$apiBaseUrl string API base URL. yii\authclient\clients\Twitter
$attributeParams array List of extra parameters, which should be used, while requesting user attributes from Twitter API. yii\authclient\clients\Twitter
$authUrl string Authorize URL. yii\authclient\clients\Twitter
$authorizationHeaderMethods array|null List of the request methods, which require adding 'Authorization' header. yii\authclient\OAuth1
$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. yii\base\Component
$consumerKey string OAuth consumer key. yii\authclient\OAuth1
$consumerSecret string OAuth consumer secret. yii\authclient\OAuth1
$httpClient yii\httpclient\Client Internal HTTP client. 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. yii\authclient\BaseClient
$requestTokenMethod string Request token HTTP method. yii\authclient\clients\Twitter
$requestTokenUrl string OAuth request token URL. yii\authclient\clients\Twitter
$returnUrl string Return URL. yii\authclient\BaseOAuth
$scope string Auth request scope. yii\authclient\BaseOAuth
$signatureMethod yii\authclient\signature\BaseMethod Signature method instance. yii\authclient\BaseOAuth
$stateStorage yii\authclient\StateStorageInterface Stage storage. 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\OAuth1
$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\OAuth1
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
beforeRequestSend() Handles yii\httpclient\Request::EVENT_BEFORE_SEND event. yii\authclient\OAuth1
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
buildAuthUrl() Composes user authorization URL. yii\authclient\OAuth1
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\OAuth1
createRequest() Creates HTTP request instance. yii\authclient\OAuth1
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 OAuth access token. yii\authclient\OAuth1
fetchRequestToken() Fetches the OAuth request token. yii\authclient\OAuth1
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\BaseClient
getName() yii\authclient\BaseClient
getNormalizeUserAttributeMap() yii\authclient\BaseClient
getRequestOptions() yii\authclient\BaseClient
getReturnUrl() yii\authclient\BaseOAuth
getSignatureMethod() yii\authclient\BaseOAuth
getStateStorage() yii\authclient\BaseClient
getTitle() yii\authclient\BaseClient
getUserAttributes() yii\authclient\BaseClient
getViewOptions() yii\authclient\BaseClient
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\OAuth1
setAccessToken() Sets access token to be used. yii\authclient\BaseOAuth
setHttpClient() Sets HTTP client to be used. yii\authclient\BaseOAuth
setId() yii\authclient\BaseClient
setName() yii\authclient\BaseClient
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\BaseClient
setUserAttributes() yii\authclient\BaseClient
setViewOptions() yii\authclient\BaseClient
signRequest() Sign given request with $signatureMethod. yii\authclient\OAuth1
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

Method Description Defined By
composeAuthorizationHeader() Composes authorization header. yii\authclient\OAuth1
composeSignatureBaseString() Creates signature base string, which will be signed by $signatureMethod. yii\authclient\OAuth1
composeSignatureKey() Composes request signature key. yii\authclient\OAuth1
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\clients\Twitter
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\clients\Twitter
defaultViewOptions() Returns the default $viewOptions value. yii\authclient\BaseClient
generateCommonRequestParams() Generate common request params like version, timestamp etc. yii\authclient\OAuth1
generateNonce() Generates nonce value. yii\authclient\OAuth1
generateTimestamp() Generates timestamp. yii\authclient\OAuth1
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\clients\Twitter
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

Hide inherited properties

$accessTokenMethod public property

Access token HTTP method.

public string $accessTokenMethod 'POST'
$accessTokenUrl public property

OAuth access token URL.

public string $accessTokenUrl 'https://api.twitter.com/oauth/access_token'
$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 'https://api.twitter.com/1.1'
$attributeParams public property (available since version 2.0.6)

List of extra parameters, which should be used, while requesting user attributes from Twitter API. For example:

[
    'include_email' => 'true'
]

See also https://dev.twitter.com/rest/reference/get/account/verify_credentials.

public array $attributeParams = []
$authUrl public property

Authorize URL.

public string $authUrl 'https://api.twitter.com/oauth/authenticate'
$requestTokenMethod public property

Request token HTTP method.

public string $requestTokenMethod 'POST'
$requestTokenUrl public property

OAuth request token URL.

public string $requestTokenUrl 'https://api.twitter.com/oauth/request_token'

Method Details

Hide inherited methods

__call() public method

Defined in: yii\base\Component::__call()

Calls the named method which is not a class method.

This method will check if any attached behavior has the named method and will execute it if available.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name string

The method name

$params array

Method parameters

return mixed

The method return value

throws yii\base\UnknownMethodException

when calling unknown method

                public function __call($name, $params)
{
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $object) {
        if ($object->hasMethod($name)) {
            return call_user_func_array([$object, $name], $params);
        }
    }
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__clone() public method

Defined in: yii\base\Component::__clone()

This method is called after the object is created by cloning an existing one.

It removes all behaviors because they are attached to the old object.

public void __clone ( )

                public function __clone()
{
    $this->_events = [];
    $this->_eventWildcards = [];
    $this->_behaviors = null;
}

            
__construct() public method

Defined in: yii\base\BaseObject::__construct()

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
public void __construct ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() public method

Defined in: yii\base\Component::__get()

Returns the value of a component property.

This method will check in the following order and act accordingly:

  • a property defined by a getter: return the getter result
  • a property of a behavior: return the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $component->property;.

See also __set().

public mixed __get ( $name )
$name string

The property name

return mixed

The property value or the value of a behavior's property

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is write-only.

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        // read property, e.g. getName()
        return $this->$getter();
    }
    // behavior property
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $behavior) {
        if ($behavior->canGetProperty($name)) {
            return $behavior->$name;
        }
    }
    if (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public method

Defined in: yii\base\Component::__isset()

Checks if a property is set, i.e. defined and not null.

This method will check in the following order and act accordingly:

  • a property defined by a setter: return whether the property is set
  • a property of a behavior: return whether the property is set
  • return false for non existing properties

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($component->property).

See also https://www.php.net/manual/en/function.isset.php.

public boolean __isset ( $name )
$name string

The property name or the event name

return boolean

Whether the named property is set

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    // behavior property
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $behavior) {
        if ($behavior->canGetProperty($name)) {
            return $behavior->$name !== null;
        }
    }
    return false;
}

            
__set() public method

Defined in: yii\base\Component::__set()

Sets the value of a component property.

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value
  • an event in the format of "on xyz": attach the handler to the event "xyz"
  • a behavior in the format of "as xyz": attach the behavior named as "xyz"
  • a property of a behavior: set the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.

See also __get().

public void __set ( $name, $value )
$name string

The property name or the event name

$value mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is read-only.

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        // set property
        $this->$setter($value);
        return;
    } elseif (strncmp($name, 'on ', 3) === 0) {
        // on event: attach event handler
        $this->on(trim(substr($name, 3)), $value);
        return;
    } elseif (strncmp($name, 'as ', 3) === 0) {
        // as behavior: attach behavior
        $name = trim(substr($name, 3));
        $this->attachBehavior($name, $value instanceof Behavior ? $value : Yii::createObject($value));
        return;
    }
    // behavior property
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $behavior) {
        if ($behavior->canSetProperty($name)) {
            $behavior->$name = $value;
            return;
        }
    }
    if (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}

            
__unset() public method

Defined in: yii\base\Component::__unset()

Sets a component property to be null.

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value to be null
  • a property of a behavior: set the property value to be null

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($component->property).

See also https://www.php.net/manual/en/function.unset.php.

public void __unset ( $name )
$name string

The property name

throws yii\base\InvalidCallException

if the property is read only.

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
        return;
    }
    // behavior property
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $behavior) {
        if ($behavior->canSetProperty($name)) {
            $behavior->$name = null;
            return;
        }
    }
    throw new InvalidCallException('Unsetting an unknown or read-only property: ' . get_class($this) . '::' . $name);
}

            
api() public method

Defined in: yii\authclient\BaseOAuth::api()

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|array

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.

                public function api($apiSubUrl, $method = 'GET', $data = [], $headers = [])
{
    $request = $this->createApiRequest()
        ->setMethod($method)
        ->setUrl($apiSubUrl)
        ->addHeaders($headers);
    if (!empty($data)) {
        if (is_array($data)) {
            $request->setData($data);
        } else {
            $request->setContent($data);
        }
    }
    return $this->sendRequest($request);
}

            
applyAccessTokenToRequest() public method (available since version 2.1)

Defined in: yii\authclient\OAuth1::applyAccessTokenToRequest()

Applies access token to the HTTP request instance.

public void applyAccessTokenToRequest ( $request, $accessToken )
$request yii\httpclient\Request

HTTP request instance.

$accessToken yii\authclient\OAuthToken

Access token instance.

                public function applyAccessTokenToRequest($request, $accessToken)
{
    $data = $request->getData();
    $data['oauth_consumer_key'] = $this->consumerKey;
    $data['oauth_token'] = $accessToken->getToken();
    $request->setData($data);
}

            
attachBehavior() public method

Defined in: yii\base\Component::attachBehavior()

Attaches a behavior to this component.

This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the yii\base\Behavior::attach() method.

See also detachBehavior().

public yii\base\Behavior attachBehavior ( $name, $behavior )
$name string

The name of the behavior.

$behavior string|array|yii\base\Behavior

The behavior configuration. This can be one of the following:

return yii\base\Behavior

The behavior object

                public function attachBehavior($name, $behavior)
{
    $this->ensureBehaviors();
    return $this->attachBehaviorInternal($name, $behavior);
}

            
attachBehaviors() public method

Defined in: yii\base\Component::attachBehaviors()

Attaches a list of behaviors to the component.

Each behavior is indexed by its name and should be a yii\base\Behavior object, a string specifying the behavior class, or an configuration array for creating the behavior.

See also attachBehavior().

public void attachBehaviors ( $behaviors )
$behaviors array

List of behaviors to be attached to the component

                public function attachBehaviors($behaviors)
{
    $this->ensureBehaviors();
    foreach ($behaviors as $name => $behavior) {
        $this->attachBehaviorInternal($name, $behavior);
    }
}

            
beforeApiRequestSend() public method (available since version 2.1)
public void beforeApiRequestSend ( $event )
$event yii\httpclient\RequestEvent

Event instance.

throws yii\base\Exception

on invalid access token.

                public function beforeApiRequestSend($event)
{
    $accessToken = $this->getAccessToken();
    if (!is_object($accessToken) || (!$accessToken->getIsValid() && !$this->autoRefreshAccessToken)) {
        throw new Exception('Invalid access token.');
    } elseif ($accessToken->getIsExpired() && $this->autoRefreshAccessToken) {
        $accessToken = $this->refreshAccessToken($accessToken);
    }
    $this->applyAccessTokenToRequest($event->request, $accessToken);
}

            
beforeRequestSend() public method (available since version 2.1)

Defined in: yii\authclient\OAuth1::beforeRequestSend()

Handles yii\httpclient\Request::EVENT_BEFORE_SEND event.

Ensures every request has been signed up before sending.

public void beforeRequestSend ( $event )
$event yii\httpclient\RequestEvent

Event instance.

                public function beforeRequestSend($event)
{
    $this->signRequest($event->request);
}

            
behaviors() public method

Defined in: yii\base\Component::behaviors()

Returns a list of behaviors that this component should behave as.

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from yii\base\Behavior. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using getBehavior() or be detached using detachBehavior(). Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

public array behaviors ( )
return array

The behavior configurations.

                public function behaviors()
{
    return [];
}

            
buildAuthUrl() public method

Defined in: yii\authclient\OAuth1::buildAuthUrl()

Composes user authorization URL.

public string buildAuthUrl ( yii\authclient\OAuthToken $requestToken null, array $params = [] )
$requestToken yii\authclient\OAuthToken

OAuth request token.

$params array

Additional request params.

return string

Authorize URL

throws yii\base\InvalidParamException

on failure.

                public function buildAuthUrl(OAuthToken $requestToken = null, array $params = [])
{
    if (!is_object($requestToken)) {
        $requestToken = $this->getState('requestToken');
        if (!is_object($requestToken)) {
            throw new InvalidParamException('Request token is required to build authorize URL!');
        }
    }
    $params['oauth_token'] = $requestToken->getToken();
    return $this->composeUrl($this->authUrl, $params);
}

            
canGetProperty() public method

Defined in: yii\base\Component::canGetProperty()

Returns a value indicating whether a property can be read.

A property can be read if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a readable property of the given name (when $checkBehaviors is true).

See also canSetProperty().

public boolean canGetProperty ( $name, $checkVars true, $checkBehaviors true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

$checkBehaviors boolean

Whether to treat behaviors' properties as properties of this component

return boolean

Whether the property can be read

                public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
{
    if (method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name)) {
        return true;
    } elseif ($checkBehaviors) {
        $this->ensureBehaviors();
        foreach ($this->_behaviors as $behavior) {
            if ($behavior->canGetProperty($name, $checkVars)) {
                return true;
            }
        }
    }
    return false;
}

            
canSetProperty() public method

Defined in: yii\base\Component::canSetProperty()

Returns a value indicating whether a property can be set.

A property can be written if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a writable property of the given name (when $checkBehaviors is true).

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars true, $checkBehaviors true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

$checkBehaviors boolean

Whether to treat behaviors' properties as properties of this component

return boolean

Whether the property can be written

                public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)
{
    if (method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name)) {
        return true;
    } elseif ($checkBehaviors) {
        $this->ensureBehaviors();
        foreach ($this->_behaviors as $behavior) {
            if ($behavior->canSetProperty($name, $checkVars)) {
                return true;
            }
        }
    }
    return false;
}

            
className() public static method
Deprecated since 2.0.14. On PHP >=5.5, use ::class instead.

Defined in: yii\base\BaseObject::className()

Returns the fully qualified name of this class.

public static string className ( )
return string

The fully qualified name of this class.

                public static function className()
{
    return get_called_class();
}

            
composeAuthorizationHeader() protected method

Defined in: yii\authclient\OAuth1::composeAuthorizationHeader()

Composes authorization header.

protected array composeAuthorizationHeader ( array $params, $realm '' )
$params array

Request params.

$realm string

Authorization realm.

return array

Authorization header in format: [name => content].

                protected function composeAuthorizationHeader(array $params, $realm = '')
{
    $header = 'OAuth';
    $headerParams = [];
    if (!empty($realm)) {
        $headerParams[] = 'realm="' . rawurlencode($realm) . '"';
    }
    foreach ($params as $key => $value) {
        if (substr_compare($key, 'oauth', 0, 5)) {
            continue;
        }
        $headerParams[] = rawurlencode($key) . '="' . rawurlencode($value) . '"';
    }
    if (!empty($headerParams)) {
        $header .= ' ' . implode(', ', $headerParams);
    }
    return ['Authorization' => $header];
}

            
composeSignatureBaseString() protected method

Defined in: yii\authclient\OAuth1::composeSignatureBaseString()

Creates signature base string, which will be signed by $signatureMethod.

protected string composeSignatureBaseString ( $method, $url, array $params )
$method string

Request method.

$url string

Request URL.

$params array

Request params.

return string

Base signature string.

                protected function composeSignatureBaseString($method, $url, array $params)
{
    if (strpos($url, '?') !== false) {
        list($url, $queryString) = explode('?', $url, 2);
        parse_str($queryString, $urlParams);
        $params = array_merge($urlParams, $params);
    }
    unset($params['oauth_signature']);
    uksort($params, 'strcmp'); // Parameters are sorted by name, using lexicographical byte value ordering. Ref: Spec: 9.1.1
    $parts = [
        strtoupper($method),
        $url,
        http_build_query($params, '', '&', PHP_QUERY_RFC3986)
    ];
    $parts = array_map('rawurlencode', $parts);
    return implode('&', $parts);
}

            
composeSignatureKey() protected method

Defined in: yii\authclient\OAuth1::composeSignatureKey()

Composes request signature key.

protected string composeSignatureKey ( $token null )
$token yii\authclient\OAuthToken|null

OAuth token to be used for signature key.

return string

Signature key.

                protected function composeSignatureKey($token = null)
{
    $signatureKeyParts = [
        $this->consumerSecret
    ];
    if ($token === null) {
        $token = $this->getAccessToken();
    }
    if (is_object($token)) {
        $signatureKeyParts[] = $token->getTokenSecret();
    } else {
        $signatureKeyParts[] = '';
    }
    $signatureKeyParts = array_map('rawurlencode', $signatureKeyParts);
    return implode('&', $signatureKeyParts);
}

            
composeUrl() protected method

Defined in: yii\authclient\BaseOAuth::composeUrl()

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.

                protected function composeUrl($url, array $params = [])
{
    if (!empty($params)) {
        if (strpos($url, '?') === false) {
            $url .= '?';
        } else {
            $url .= '&';
        }
        $url .= http_build_query($params, '', '&', PHP_QUERY_RFC3986);
    }
    return $url;
}

            
createApiRequest() public method (available since version 2.1)

Defined in: yii\authclient\OAuth1::createApiRequest()

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.

public yii\httpclient\Request createApiRequest ( )
return yii\httpclient\Request

HTTP request instance.

                public function createApiRequest()
{
    $request = parent::createApiRequest();
    // ensure correct event handlers order :
    $request->off(Request::EVENT_BEFORE_SEND, [$this, 'beforeRequestSend']);
    $request->on(Request::EVENT_BEFORE_SEND, [$this, 'beforeRequestSend']);
    return $request;
}

            
createHttpClient() protected method (available since version 2.1)

Defined in: yii\authclient\BaseOAuth::createHttpClient()

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.

                protected function createHttpClient($reference)
{
    $httpClient = parent::createHttpClient($reference);
    $httpClient->baseUrl = $this->apiBaseUrl;
    return $httpClient;
}

            
createRequest() public method (available since version 2.1)

Defined in: yii\authclient\OAuth1::createRequest()

Creates HTTP request instance.

public yii\httpclient\Request createRequest ( )
return yii\httpclient\Request

HTTP request instance.

                public function createRequest()
{
    $request = parent::createRequest();
    $request->on(Request::EVENT_BEFORE_SEND, [$this, 'beforeRequestSend']);
    return $request;
}

            
createSignatureMethod() protected method

Defined in: yii\authclient\BaseOAuth::createSignatureMethod()

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.

                protected function createSignatureMethod(array $signatureMethodConfig)
{
    if (!array_key_exists('class', $signatureMethodConfig)) {
        $signatureMethodConfig['class'] = signature\HmacSha1::className();
    }
    return Yii::createObject($signatureMethodConfig);
}

            
createToken() protected method

Defined in: yii\authclient\BaseOAuth::createToken()

Creates token from its configuration.

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

Token configuration.

return yii\authclient\OAuthToken

Token instance.

                protected function createToken(array $tokenConfig = [])
{
    if (!array_key_exists('class', $tokenConfig)) {
        $tokenConfig['class'] = OAuthToken::className();
    }
    return Yii::createObject($tokenConfig);
}

            
defaultName() protected method

Generates service name.

protected string defaultName ( )
return string

Service name.

                protected function defaultName()
{
    return 'twitter';
}

            
defaultNormalizeUserAttributeMap() protected method

Defined in: yii\authclient\BaseClient::defaultNormalizeUserAttributeMap()

Returns the default $normalizeUserAttributeMap value.

Particular client may override this method in order to provide specific default map.

protected array defaultNormalizeUserAttributeMap ( )
return array

Normalize attribute map.

                protected function defaultNormalizeUserAttributeMap()
{
    return [];
}

            
defaultRequestOptions() protected method (available since version 2.1)

Defined in: yii\authclient\BaseOAuth::defaultRequestOptions()

Returns default HTTP request options.

protected array defaultRequestOptions ( )
return array

HTTP request options.

                protected function defaultRequestOptions()
{
    return [
        'userAgent' => Inflector::slug(Yii::$app->name) . ' OAuth ' . $this->version . ' Client',
        'timeout' => 30,
    ];
}

            
defaultReturnUrl() protected method

Defined in: yii\authclient\BaseOAuth::defaultReturnUrl()

Composes default $returnUrl value.

protected string defaultReturnUrl ( )
return string

Return URL.

                protected function defaultReturnUrl()
{
    $params = Yii::$app->getRequest()->getQueryParams();
    $params = array_intersect_key($params, array_flip($this->parametersToKeepInReturnUrl));
    $params[0] = Yii::$app->controller->getRoute();
    return Yii::$app->getUrlManager()->createAbsoluteUrl($params);
}

            
defaultTitle() protected method

Generates service title.

protected string defaultTitle ( )
return string

Service title.

                protected function defaultTitle()
{
    return 'Twitter';
}

            
defaultViewOptions() protected method

Defined in: yii\authclient\BaseClient::defaultViewOptions()

Returns the default $viewOptions value.

Particular client may override this method in order to provide specific default view options.

protected array defaultViewOptions ( )
return array

List of default $viewOptions

                protected function defaultViewOptions()
{
    return [];
}

            
detachBehavior() public method

Defined in: yii\base\Component::detachBehavior()

Detaches a behavior from the component.

The behavior's yii\base\Behavior::detach() method will be invoked.

public yii\base\Behavior|null detachBehavior ( $name )
$name string

The behavior's name.

return yii\base\Behavior|null

The detached behavior. Null if the behavior does not exist.

                public function detachBehavior($name)
{
    $this->ensureBehaviors();
    if (isset($this->_behaviors[$name])) {
        $behavior = $this->_behaviors[$name];
        unset($this->_behaviors[$name]);
        $behavior->detach();
        return $behavior;
    }
    return null;
}

            
detachBehaviors() public method

Defined in: yii\base\Component::detachBehaviors()

Detaches all behaviors from the component.

public void detachBehaviors ( )

                public function detachBehaviors()
{
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $name => $behavior) {
        $this->detachBehavior($name);
    }
}

            
ensureBehaviors() public method

Defined in: yii\base\Component::ensureBehaviors()

Makes sure that the behaviors declared in behaviors() are attached to this component.

public void ensureBehaviors ( )

                public function ensureBehaviors()
{
    if ($this->_behaviors === null) {
        $this->_behaviors = [];
        foreach ($this->behaviors() as $name => $behavior) {
            $this->attachBehaviorInternal($name, $behavior);
        }
    }
}

            
fetchAccessToken() public method

Defined in: yii\authclient\OAuth1::fetchAccessToken()

Fetches OAuth access token.

public yii\authclient\OAuthToken fetchAccessToken ( $oauthToken null, yii\authclient\OAuthToken $requestToken null, $oauthVerifier null, array $params = [] )
$oauthToken string

OAuth token returned with redirection back to client.

$requestToken yii\authclient\OAuthToken

OAuth request token.

$oauthVerifier string

OAuth verifier.

$params array

Additional request params.

return yii\authclient\OAuthToken

OAuth access token.

throws yii\base\InvalidParamException

on failure.

throws yii\web\HttpException

in case oauth token miss-matches request token.

                public function fetchAccessToken($oauthToken = null, OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
{
    $incomingRequest = Yii::$app->getRequest();
    if ($oauthToken === null) {
        $oauthToken = $incomingRequest->get('oauth_token', $incomingRequest->post('oauth_token', $oauthToken));
    }
    if (!is_object($requestToken)) {
        $requestToken = $this->getState('requestToken');
        if (!is_object($requestToken)) {
            throw new InvalidParamException('Request token is required to fetch access token!');
        }
    }
    if (!Yii::$app->getSecurity()->compareString($requestToken->getToken(), $oauthToken)) {
        throw new HttpException(400, 'Invalid auth state parameter.');
    }
    $this->removeState('requestToken');
    $defaultParams = [
        'oauth_consumer_key' => $this->consumerKey,
        'oauth_token' => $requestToken->getToken()
    ];
    if ($oauthVerifier === null) {
        $oauthVerifier = $incomingRequest->get('oauth_verifier', $incomingRequest->post('oauth_verifier'));
    }
    if (!empty($oauthVerifier)) {
        $defaultParams['oauth_verifier'] = $oauthVerifier;
    }
    $request = $this->createRequest()
        ->setMethod($this->accessTokenMethod)
        ->setUrl($this->accessTokenUrl)
        ->setData(array_merge($defaultParams, $params));
    $this->signRequest($request, $requestToken);
    $response = $this->sendRequest($request);
    $token = $this->createToken([
        'params' => $response
    ]);
    $this->setAccessToken($token);
    return $token;
}

            
fetchRequestToken() public method

Defined in: yii\authclient\OAuth1::fetchRequestToken()

Fetches the OAuth request token.

public yii\authclient\OAuthToken fetchRequestToken ( array $params = [] )
$params array

Additional request params.

return yii\authclient\OAuthToken

Request token.

                public function fetchRequestToken(array $params = [])
{
    $this->setAccessToken(null);
    $defaultParams = [
        'oauth_consumer_key' => $this->consumerKey,
        'oauth_callback' => $this->getReturnUrl(),
        //'xoauth_displayname' => Yii::$app->name,
    ];
    if (!empty($this->scope)) {
        $defaultParams['scope'] = $this->scope;
    }
    $request = $this->createRequest()
        ->setMethod($this->requestTokenMethod)
        ->setUrl($this->requestTokenUrl)
        ->setData(array_merge($defaultParams, $params));
    $this->signRequest($request);
    $response = $this->sendRequest($request);
    $token = $this->createToken([
        'params' => $response
    ]);
    $this->setState('requestToken', $token);
    return $token;
}

            
generateCommonRequestParams() protected method

Defined in: yii\authclient\OAuth1::generateCommonRequestParams()

Generate common request params like version, timestamp etc.

protected array generateCommonRequestParams ( )
return array

Common request params.

                protected function generateCommonRequestParams()
{
    $params = [
        'oauth_version' => $this->version,
        'oauth_nonce' => $this->generateNonce(),
        'oauth_timestamp' => $this->generateTimestamp(),
    ];
    return $params;
}

            
generateNonce() protected method

Defined in: yii\authclient\OAuth1::generateNonce()

Generates nonce value.

protected string generateNonce ( )
return string

Nonce value.

                protected function generateNonce()
{
    return md5(microtime() . random_int(0, PHP_INT_MAX));
}

            
generateTimestamp() protected method

Defined in: yii\authclient\OAuth1::generateTimestamp()

Generates timestamp.

protected integer generateTimestamp ( )
return integer

Timestamp.

                protected function generateTimestamp()
{
    return time();
}

            
getAccessToken() public method
public yii\authclient\OAuthToken getAccessToken ( )
return yii\authclient\OAuthToken

Auth token instance.

                public function getAccessToken()
{
    if (!is_object($this->_accessToken)) {
        $this->_accessToken = $this->restoreAccessToken();
    }
    return $this->_accessToken;
}

            
getBehavior() public method

Defined in: yii\base\Component::getBehavior()

Returns the named behavior object.

public yii\base\Behavior|null getBehavior ( $name )
$name string

The behavior name

return yii\base\Behavior|null

The behavior object, or null if the behavior does not exist

                public function getBehavior($name)
{
    $this->ensureBehaviors();
    return isset($this->_behaviors[$name]) ? $this->_behaviors[$name] : null;
}

            
getBehaviors() public method

Defined in: yii\base\Component::getBehaviors()

Returns all behaviors attached to this component.

public yii\base\Behavior[] getBehaviors ( )
return yii\base\Behavior[]

List of behaviors attached to this component

                public function getBehaviors()
{
    $this->ensureBehaviors();
    return $this->_behaviors;
}

            
getHttpClient() public method (available since version 2.1)

Defined in: yii\authclient\BaseClient::getHttpClient()

Returns HTTP client.

public yii\httpclient\Client getHttpClient ( )
return yii\httpclient\Client

Internal HTTP client.

                public function getHttpClient()
{
    if (!is_object($this->_httpClient)) {
        $this->_httpClient = $this->createHttpClient($this->_httpClient);
    }
    return $this->_httpClient;
}

            
getId() public method
public string getId ( )
return string

Service id

                public function getId()
{
    if (empty($this->_id)) {
        $this->_id = $this->getName();
    }
    return $this->_id;
}

            
getName() public method
public string getName ( )
return string

Service name.

                public function getName()
{
    if ($this->_name === null) {
        $this->_name = $this->defaultName();
    }
    return $this->_name;
}

            
getNormalizeUserAttributeMap() public method
public array getNormalizeUserAttributeMap ( )
return array

Normalize user attribute map.

                public function getNormalizeUserAttributeMap()
{
    if ($this->_normalizeUserAttributeMap === null) {
        $this->_normalizeUserAttributeMap = $this->defaultNormalizeUserAttributeMap();
    }
    return $this->_normalizeUserAttributeMap;
}

            
getRequestOptions() public method (available since version 2.1)
public array getRequestOptions ( )
return array

HTTP request options.

                public function getRequestOptions()
{
    return $this->_requestOptions;
}

            
getReturnUrl() public method
public string getReturnUrl ( )
return string

Return URL.

                public function getReturnUrl()
{
    if ($this->_returnUrl === null) {
        $this->_returnUrl = $this->defaultReturnUrl();
    }
    return $this->_returnUrl;
}

            
getSignatureMethod() public method
public yii\authclient\signature\BaseMethod getSignatureMethod ( )
return yii\authclient\signature\BaseMethod

Signature method instance.

                public function getSignatureMethod()
{
    if (!is_object($this->_signatureMethod)) {
        $this->_signatureMethod = $this->createSignatureMethod($this->_signatureMethod);
    }
    return $this->_signatureMethod;
}

            
getState() protected method

Defined in: yii\authclient\BaseClient::getState()

Returns persistent state value.

protected mixed getState ( $key )
$key string

State key.

return mixed

State value.

                protected function getState($key)
{
    return $this->getStateStorage()->get($this->getStateKeyPrefix() . $key);
}

            
getStateKeyPrefix() protected method

Defined in: yii\authclient\BaseClient::getStateKeyPrefix()

Returns session key prefix, which is used to store internal states.

protected string getStateKeyPrefix ( )
return string

Session key prefix.

                protected function getStateKeyPrefix()
{
    return get_class($this) . '_' . $this->getId() . '_';
}

            
getStateStorage() public method
public yii\authclient\StateStorageInterface getStateStorage ( )
return yii\authclient\StateStorageInterface

Stage storage.

                public function getStateStorage()
{
    if (!is_object($this->_stateStorage)) {
        $this->_stateStorage = Yii::createObject($this->_stateStorage);
    }
    return $this->_stateStorage;
}

            
getTitle() public method
public string getTitle ( )
return string

Service title.

                public function getTitle()
{
    if ($this->_title === null) {
        $this->_title = $this->defaultTitle();
    }
    return $this->_title;
}

            
getUserAttributes() public method
public array getUserAttributes ( )
return array

List of user attributes

                public function getUserAttributes()
{
    if ($this->_userAttributes === null) {
        $this->_userAttributes = $this->normalizeUserAttributes($this->initUserAttributes());
    }
    return $this->_userAttributes;
}

            
getViewOptions() public method
public array getViewOptions ( )
return array

View options in format: optionName => optionValue

                public function getViewOptions()
{
    if ($this->_viewOptions === null) {
        $this->_viewOptions = $this->defaultViewOptions();
    }
    return $this->_viewOptions;
}

            
hasEventHandlers() public method

Defined in: yii\base\Component::hasEventHandlers()

Returns a value indicating whether there is any handler attached to the named event.

public boolean hasEventHandlers ( $name )
$name string

The event name

return boolean

Whether there is any handler attached to the event.

                public function hasEventHandlers($name)
{
    $this->ensureBehaviors();
    if (!empty($this->_events[$name])) {
        return true;
    }
    foreach ($this->_eventWildcards as $wildcard => $handlers) {
        if (!empty($handlers) && StringHelper::matchWildcard($wildcard, $name)) {
            return true;
        }
    }
    return Event::hasHandlers($this, $name);
}

            
hasMethod() public method

Defined in: yii\base\Component::hasMethod()

Returns a value indicating whether a method is defined.

A method is defined if:

  • the class has a method with the specified name
  • an attached behavior has a method with the given name (when $checkBehaviors is true).
public boolean hasMethod ( $name, $checkBehaviors true )
$name string

The property name

$checkBehaviors boolean

Whether to treat behaviors' methods as methods of this component

return boolean

Whether the method is defined

                public function hasMethod($name, $checkBehaviors = true)
{
    if (method_exists($this, $name)) {
        return true;
    } elseif ($checkBehaviors) {
        $this->ensureBehaviors();
        foreach ($this->_behaviors as $behavior) {
            if ($behavior->hasMethod($name)) {
                return true;
            }
        }
    }
    return false;
}

            
hasProperty() public method

Defined in: yii\base\Component::hasProperty()

Returns a value indicating whether a property is defined for this component.

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a property of the given name (when $checkBehaviors is true).

See also:

public boolean hasProperty ( $name, $checkVars true, $checkBehaviors true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

$checkBehaviors boolean

Whether to treat behaviors' properties as properties of this component

return boolean

Whether the property is defined

                public function hasProperty($name, $checkVars = true, $checkBehaviors = true)
{
    return $this->canGetProperty($name, $checkVars, $checkBehaviors) || $this->canSetProperty($name, false, $checkBehaviors);
}

            
init() public method

Defined in: yii\base\BaseObject::init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

                public function init()
{
}

            
initUserAttributes() protected method

Initializes authenticated user attributes.

protected array initUserAttributes ( )
return array

Auth user attributes.

                protected function initUserAttributes()
{
    return $this->api('account/verify_credentials.json', 'GET', $this->attributeParams);
}

            
normalizeUserAttributes() protected method

Defined in: yii\authclient\BaseClient::normalizeUserAttributes()

Normalize given user attributes according to $normalizeUserAttributeMap.

protected array normalizeUserAttributes ( $attributes )
$attributes array

Raw attributes.

return array

Normalized attributes.

throws yii\base\InvalidConfigException

on incorrect normalize attribute map.

                protected function normalizeUserAttributes($attributes)
{
    foreach ($this->getNormalizeUserAttributeMap() as $normalizedName => $actualName) {
        if (is_scalar($actualName)) {
            if (array_key_exists($actualName, $attributes)) {
                $attributes[$normalizedName] = $attributes[$actualName];
            }
        } else {
            if (is_callable($actualName)) {
                $attributes[$normalizedName] = call_user_func($actualName, $attributes);
            } elseif (is_array($actualName)) {
                $haystack = $attributes;
                $searchKeys = $actualName;
                $isFound = true;
                while (($key = array_shift($searchKeys)) !== null) {
                    if (is_array($haystack) && array_key_exists($key, $haystack)) {
                        $haystack = $haystack[$key];
                    } else {
                        $isFound = false;
                        break;
                    }
                }
                if ($isFound) {
                    $attributes[$normalizedName] = $haystack;
                }
            } else {
                throw new InvalidConfigException('Invalid actual name "' . gettype($actualName) . '" specified at "' . get_class($this) . '::normalizeUserAttributeMap"');
            }
        }
    }
    return $attributes;
}

            
off() public method

Defined in: yii\base\Component::off()

Detaches an existing event handler from this component.

This method is the opposite of on().

Note: in case wildcard pattern is passed for event name, only the handlers registered with this wildcard will be removed, while handlers registered with plain names matching this wildcard will remain.

See also on().

public boolean off ( $name, $handler null )
$name string

Event name

$handler callable|null

The event handler to be removed. If it is null, all handlers attached to the named event will be removed.

return boolean

If a handler is found and detached

                public function off($name, $handler = null)
{
    $this->ensureBehaviors();
    if (empty($this->_events[$name]) && empty($this->_eventWildcards[$name])) {
        return false;
    }
    if ($handler === null) {
        unset($this->_events[$name], $this->_eventWildcards[$name]);
        return true;
    }
    $removed = false;
    // plain event names
    if (isset($this->_events[$name])) {
        foreach ($this->_events[$name] as $i => $event) {
            if ($event[0] === $handler) {
                unset($this->_events[$name][$i]);
                $removed = true;
            }
        }
        if ($removed) {
            $this->_events[$name] = array_values($this->_events[$name]);
            return true;
        }
    }
    // wildcard event names
    if (isset($this->_eventWildcards[$name])) {
        foreach ($this->_eventWildcards[$name] as $i => $event) {
            if ($event[0] === $handler) {
                unset($this->_eventWildcards[$name][$i]);
                $removed = true;
            }
        }
        if ($removed) {
            $this->_eventWildcards[$name] = array_values($this->_eventWildcards[$name]);
            // remove empty wildcards to save future redundant regex checks:
            if (empty($this->_eventWildcards[$name])) {
                unset($this->_eventWildcards[$name]);
            }
        }
    }
    return $removed;
}

            
on() public method

Defined in: yii\base\Component::on()

Attaches an event handler to an event.

The event handler must be a valid PHP callback. The following are some examples:

function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()

The event handler must be defined with the following signature,

function ($event)

where $event is an yii\base\Event object which includes parameters associated with the event.

Since 2.0.14 you can specify event name as a wildcard pattern:

$component->on('event.group.*', function ($event) {
    Yii::trace($event->name . ' is triggered.');
});

See also off().

public void on ( $name, $handler, $data null, $append true )
$name string

The event name

$handler callable

The event handler

$data mixed

The data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via yii\base\Event::$data.

$append boolean

Whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.

                public function on($name, $handler, $data = null, $append = true)
{
    $this->ensureBehaviors();
    if (strpos($name, '*') !== false) {
        if ($append || empty($this->_eventWildcards[$name])) {
            $this->_eventWildcards[$name][] = [$handler, $data];
        } else {
            array_unshift($this->_eventWildcards[$name], [$handler, $data]);
        }
        return;
    }
    if ($append || empty($this->_events[$name])) {
        $this->_events[$name][] = [$handler, $data];
    } else {
        array_unshift($this->_events[$name], [$handler, $data]);
    }
}

            
refreshAccessToken() public method

Defined in: yii\authclient\OAuth1::refreshAccessToken()

Gets new auth token to replace expired one.

public yii\authclient\OAuthToken refreshAccessToken ( yii\authclient\OAuthToken $token )
$token yii\authclient\OAuthToken

Expired auth token.

return yii\authclient\OAuthToken

New auth token.

                public function refreshAccessToken(OAuthToken $token)
{
    // @todo
    return null;
}

            
removeState() protected method

Defined in: yii\authclient\BaseClient::removeState()

Removes persistent state value.

protected boolean removeState ( $key )
$key string

State key.

return boolean

Success.

                protected function removeState($key)
{
    return $this->getStateStorage()->remove($this->getStateKeyPrefix() . $key);
}

            
restoreAccessToken() protected method

Defined in: yii\authclient\BaseOAuth::restoreAccessToken()

Restores access token.

protected yii\authclient\OAuthToken restoreAccessToken ( )
return yii\authclient\OAuthToken

Auth token.

                protected function restoreAccessToken()
{
    $token = $this->getState('token');
    if (is_object($token)) {
        /* @var $token OAuthToken */
        if ($token->getIsExpired() && $this->autoRefreshAccessToken) {
            $token = $this->refreshAccessToken($token);
        }
    }
    return $token;
}

            
saveAccessToken() protected method

Defined in: yii\authclient\BaseOAuth::saveAccessToken()

Saves token as persistent state.

protected $this saveAccessToken ( $token )
$token yii\authclient\OAuthToken|null

Auth token to be saved.

return $this

The object itself.

                protected function saveAccessToken($token)
{
    return $this->setState('token', $token);
}

            
sendRequest() protected method (available since version 2.1)

Defined in: yii\authclient\BaseOAuth::sendRequest()

Sends the given HTTP request, returning response data.

protected array|string|null sendRequest ( $request )
$request yii\httpclient\Request

HTTP request to be sent.

return array|string|null

Response data.

throws yii\authclient\ClientErrorResponseException

on client error response codes.

throws yii\authclient\InvalidResponseException

on non-successful (other than client error) response codes.

throws yii\httpclient\Exception

                protected function sendRequest($request)
{
    $response = $request->send();
    if (!$response->getIsOk()) {
        $statusCode = (int)$response->getStatusCode();
        if ($statusCode >= 400 && $statusCode < 500) {
            $exceptionClass = 'yii\\authclient\\ClientErrorResponseException';
        } else {
            $exceptionClass = 'yii\\authclient\\InvalidResponseException';
        }
        throw new $exceptionClass(
            $response,
            'Request failed with code: ' . $statusCode . ', message: ' . $response->getContent(),
            $statusCode
        );
    }
    if (stripos($response->headers->get('content-type', ''), 'application/jwt') !== false) {
        return $response->getContent();
    } else {
        return $response->getData();
    }
}

            
setAccessToken() public method

Defined in: yii\authclient\BaseOAuth::setAccessToken()

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.

                public function setAccessToken($token)
{
    if (!is_object($token) && $token !== null) {
        $token = $this->createToken($token);
    }
    $this->_accessToken = $token;
    $this->saveAccessToken($token);
}

            
setHttpClient() public method (available since version 2.1)

Defined in: yii\authclient\BaseOAuth::setHttpClient()

Sets HTTP client to be used.

public void setHttpClient ( $httpClient )
$httpClient array|yii\httpclient\Client

Internal HTTP client.

                public function setHttpClient($httpClient)
{
    if (is_object($httpClient)) {
        $httpClient = clone $httpClient;
        $httpClient->baseUrl = $this->apiBaseUrl;
    }
    parent::setHttpClient($httpClient);
}

            
setId() public method
public void setId ( $id )
$id string

Service id.

                public function setId($id)
{
    $this->_id = $id;
}

            
setName() public method
public void setName ( $name )
$name string

Service name.

                public function setName($name)
{
    $this->_name = $name;
}

            
setNormalizeUserAttributeMap() public method
public void setNormalizeUserAttributeMap ( $normalizeUserAttributeMap )
$normalizeUserAttributeMap array

Normalize user attribute map.

                public function setNormalizeUserAttributeMap($normalizeUserAttributeMap)
{
    $this->_normalizeUserAttributeMap = $normalizeUserAttributeMap;
}

            
setRequestOptions() public method (available since version 2.1)
public void setRequestOptions ( array $options )
$options array

HTTP request options.

                public function setRequestOptions(array $options)
{
    $this->_requestOptions = $options;
}

            
setReturnUrl() public method
public void setReturnUrl ( $returnUrl )
$returnUrl string

Return URL

                public function setReturnUrl($returnUrl)
{
    $this->_returnUrl = $returnUrl;
}

            
setSignatureMethod() public method

Defined in: yii\authclient\BaseOAuth::setSignatureMethod()

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.

                public function setSignatureMethod($signatureMethod)
{
    if (!is_object($signatureMethod) && !is_array($signatureMethod)) {
        throw new InvalidArgumentException('"' . get_class($this) . '::signatureMethod" should be instance of "\yii\autclient\signature\BaseMethod" or its array configuration. "' . gettype($signatureMethod) . '" has been given.');
    }
    $this->_signatureMethod = $signatureMethod;
}

            
setState() protected method

Defined in: yii\authclient\BaseClient::setState()

Sets persistent state.

protected $this setState ( $key, $value )
$key string

State key.

$value mixed

State value

return $this

The object itself

                protected function setState($key, $value)
{
    $this->getStateStorage()->set($this->getStateKeyPrefix() . $key, $value);
    return $this;
}

            
setStateStorage() public method
public void setStateStorage ( $stateStorage )
$stateStorage yii\authclient\StateStorageInterface|array|string

Stage storage to be used.

                public function setStateStorage($stateStorage)
{
    $this->_stateStorage = $stateStorage;
}

            
setTitle() public method
public void setTitle ( $title )
$title string

Service title.

                public function setTitle($title)
{
    $this->_title = $title;
}

            
setUserAttributes() public method
public void setUserAttributes ( $userAttributes )
$userAttributes array

List of user attributes

                public function setUserAttributes($userAttributes)
{
    $this->_userAttributes = $this->normalizeUserAttributes($userAttributes);
}

            
setViewOptions() public method
public void setViewOptions ( $viewOptions )
$viewOptions array

View options in format: optionName => optionValue

                public function setViewOptions($viewOptions)
{
    $this->_viewOptions = $viewOptions;
}

            
signRequest() public method

Defined in: yii\authclient\OAuth1::signRequest()

Sign given request with $signatureMethod.

public void signRequest ( $request, $token null )
$request yii\httpclient\Request

Request instance.

$token yii\authclient\OAuthToken|null

OAuth token to be used for signature, if not set $accessToken will be used.

Version Description
2.1 this method is public.

                public function signRequest($request, $token = null)
{
    $params = $request->getData();
    if (isset($params['oauth_signature_method']) || $request->hasHeaders() && $request->getHeaders()->has('authorization')) {
        // avoid double sign of request
        return;
    }
    if (empty($params)) {
        $params = $this->generateCommonRequestParams();
    } else {
        $params = array_merge($this->generateCommonRequestParams(), $params);
    }
    $url = $request->getFullUrl();
    $signatureMethod = $this->getSignatureMethod();
    $params['oauth_signature_method'] = $signatureMethod->getName();
    $signatureBaseString = $this->composeSignatureBaseString($request->getMethod(), $url, $params);
    $signatureKey = $this->composeSignatureKey($token);
    $params['oauth_signature'] = $signatureMethod->generateSignature($signatureBaseString, $signatureKey);
    if ($this->authorizationHeaderMethods === null || in_array(strtoupper($request->getMethod()), array_map('strtoupper', $this->authorizationHeaderMethods), true)) {
        $authorizationHeader = $this->composeAuthorizationHeader($params);
        if (!empty($authorizationHeader)) {
            $request->addHeaders($authorizationHeader);
            // removing authorization header params, avoiding duplicate param server error :
            foreach ($params as $key => $value) {
                if (substr_compare($key, 'oauth', 0, 5) === 0) {
                    unset($params[$key]);
                }
            }
        }
    }
    $request->setData($params);
}

            
trigger() public method

Defined in: yii\base\Component::trigger()

Triggers an event.

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.

public void trigger ( $name, yii\base\Event $event null )
$name string

The event name

$event yii\base\Event|null

The event instance. If not set, a default yii\base\Event object will be created.

                public function trigger($name, Event $event = null)
{
    $this->ensureBehaviors();
    $eventHandlers = [];
    foreach ($this->_eventWildcards as $wildcard => $handlers) {
        if (StringHelper::matchWildcard($wildcard, $name)) {
            $eventHandlers[] = $handlers;
        }
    }
    if (!empty($this->_events[$name])) {
        $eventHandlers[] = $this->_events[$name];
    }
    if (!empty($eventHandlers)) {
        $eventHandlers = call_user_func_array('array_merge', $eventHandlers);
        if ($event === null) {
            $event = new Event();
        }
        if ($event->sender === null) {
            $event->sender = $this;
        }
        $event->handled = false;
        $event->name = $name;
        foreach ($eventHandlers as $handler) {
            $event->data = $handler[1];
            call_user_func($handler[0], $event);
            // stop further handling if the event is handled
            if ($event->handled) {
                return;
            }
        }
    }
    // invoke class-level attached handlers
    Event::trigger($this, $name, $event);
}