Class yii\authclient\OAuth1

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

OAuth1 serves as a client for the OAuth 1/1.0a flow.

In order to acquire access token perform following sequence:

use yii\authclient\OAuth1;

$oauthClient = new OAuth1();
$requestToken = $oauthClient->fetchRequestToken(); // Get request token
$url = $oauthClient->buildAuthUrl($requestToken); // Get authorization URL
return Yii::$app->getResponse()->redirect($url); // Redirect to authorization URL
// After user returns at our site:
$accessToken = $oauthClient->fetchAccessToken($requestToken); // Upgrade to access token

See also http://oauth.net/.

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\OAuth1
$accessTokenUrl string OAuth access token URL. yii\authclient\OAuth1
$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
$consumerKey string OAuth consumer key. yii\authclient\OAuth1
$consumerSecret string OAuth consumer secret. yii\authclient\OAuth1
$curlOptions array CURL options. yii\authclient\BaseOAuth
$id string Service id. yii\authclient\BaseClient
$name string Service name. yii\authclient\BaseClient
$normalizeUserAttributeMap array Normalize user attribute map. yii\authclient\BaseClient
$requestTokenMethod string Request token HTTP method. yii\authclient\OAuth1
$requestTokenUrl string OAuth request token URL. yii\authclient\OAuth1
$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
$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

Protected Methods

Hide inherited methods

Method Description Defined By
apiInternal() Performs request to the OAuth API. yii\authclient\OAuth1
composeAuthorizationHeader() Composes authorization header content. yii\authclient\OAuth1
composeRequestCurlOptions() Composes HTTP request CUrl options, which will be merged with the default ones. 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
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\BaseOAuth
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\OAuth1
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
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\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
sendSignedRequest() Sends HTTP request, signed by $signatureMethod. yii\authclient\OAuth1
setState() Sets persistent state. yii\authclient\BaseOAuth
signRequest() Sign request with $signatureMethod. yii\authclient\OAuth1

Constants

Hide inherited constants

Constant Value Description Defined By
CONTENT_TYPE_AUTO 'auto' yii\authclient\BaseOAuth
CONTENT_TYPE_JSON 'json' yii\authclient\BaseOAuth
CONTENT_TYPE_URLENCODED 'urlencoded' yii\authclient\BaseOAuth
CONTENT_TYPE_XML 'xml' yii\authclient\BaseOAuth

Property Details

Hide inherited properties

$accessTokenMethod public property

Access token HTTP method.

public string $accessTokenMethod 'GET'
$accessTokenUrl public property

OAuth access token URL.

public string $accessTokenUrl null
$consumerKey public property

OAuth consumer key.

public string $consumerKey null
$consumerSecret public property

OAuth consumer secret.

public string $consumerSecret null
$requestTokenMethod public property

Request token HTTP method.

public string $requestTokenMethod 'GET'
$requestTokenUrl public property

OAuth request token URL.

public string $requestTokenUrl null
$version public property

Protocol version.

public string $version '1.0'

Method Details

Hide inherited methods

api() public method

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

Performs request to the OAuth API.

public array api ( $apiSubUrl, $method 'GET', array $params = [], array $headers = [] )
$apiSubUrl string

API sub URL, which will be append to $apiBaseUrl, or 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.

                public function api($apiSubUrl, $method = 'GET', array $params = [], array $headers = [])
{
    if (preg_match('/^https?:\\/\\//is', $apiSubUrl)) {
        $url = $apiSubUrl;
    } else {
        $url = $this->apiBaseUrl . '/' . $apiSubUrl;
    }
    $accessToken = $this->getAccessToken();
    if (!is_object($accessToken) || !$accessToken->getIsValid()) {
        throw new Exception('Invalid access token.');
    }
    return $this->apiInternal($accessToken, $url, $method, $params, $headers);
}

            
apiInternal() protected method

Performs request to the OAuth API.

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

                protected function apiInternal($accessToken, $url, $method, array $params, array $headers)
{
    $params['oauth_consumer_key'] = $this->consumerKey;
    $params['oauth_token'] = $accessToken->getToken();
    $response = $this->sendSignedRequest($method, $url, $params, $headers);
    return $response;
}

            
buildAuthUrl() public method

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\Exception

on failure.

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

            
composeAuthorizationHeader() protected method

Composes authorization header content.

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

Request params.

$realm string

Authorization realm.

return string

Authorization header content.

                protected function composeAuthorizationHeader(array $params, $realm = '')
{
    $header = 'Authorization: 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 $header;
}

            
composeRequestCurlOptions() protected method

Composes HTTP request CUrl options, which will be merged with the default ones.

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

                protected function composeRequestCurlOptions($method, $url, array $params)
{
    $curlOptions = [];
    switch ($method) {
        case 'GET': {
            $curlOptions[CURLOPT_URL] = $this->composeUrl($url, $params);
            break;
        }
        case 'POST': {
            $curlOptions[CURLOPT_POST] = true;
            $curlOptions[CURLOPT_HTTPHEADER] = ['Content-type: application/x-www-form-urlencoded'];
            if (!empty($params)) {
                $curlOptions[CURLOPT_POSTFIELDS] = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
            }
            $authorizationHeader = $this->composeAuthorizationHeader($params);
            if (!empty($authorizationHeader)) {
                $curlOptions[CURLOPT_HTTPHEADER][] = $authorizationHeader;
            }
            break;
        }
        case 'HEAD': {
            $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
            if (!empty($params)) {
                $curlOptions[CURLOPT_URL] = $this->composeUrl($url, $params);
            }
            break;
        }
        default: {
            $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
            if (!empty($params)) {
                $curlOptions[CURLOPT_POSTFIELDS] = $params;
            }
        }
    }
    return $curlOptions;
}

            
composeSignatureBaseString() protected method

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)
{
    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

Composes request signature key.

protected string composeSignatureKey ( )
return string

Signature key.

                protected function composeSignatureKey()
{
    $signatureKeyParts = [
        $this->consumerSecret
    ];
    $accessToken = $this->getAccessToken();
    if (is_object($accessToken)) {
        $signatureKeyParts[] = $accessToken->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 (strpos($url, '?') === false) {
        $url .= '?';
    } else {
        $url .= '&';
    }
    $url .= http_build_query($params, '', '&', PHP_QUERY_RFC3986);
    return $url;
}

            
convertXmlToArray() protected method

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

Converts XML document to array.

protected array convertXmlToArray ( $xml )
$xml string|SimpleXMLElement

Xml to process.

return array

XML array representation.

                protected function convertXmlToArray($xml)
{
    if (!is_object($xml)) {
        $xml = simplexml_load_string($xml);
    }
    $result = (array) $xml;
    foreach ($result as $key => $value) {
        if (is_object($value)) {
            $result[$key] = $this->convertXmlToArray($value);
        }
    }
    return $result;
}

            
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);
}

            
defaultCurlOptions() protected method

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

Returns default cURL options.

protected array defaultCurlOptions ( )
return array

CURL options.

                protected function defaultCurlOptions()
{
    return [
        CURLOPT_USERAGENT => Yii::$app->name . ' OAuth ' . $this->version . ' Client',
        CURLOPT_CONNECTTIMEOUT => 30,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_SSL_VERIFYPEER => false,
    ];
}

            
defaultName() protected method

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

Generates service name.

protected string defaultName ( )
return string

Service name.

                protected function defaultName()
{
    return Inflector::camel2id(StringHelper::basename(get_class($this)));
}

            
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 [];
}

            
defaultReturnUrl() protected method

Composes default $returnUrl value.

protected string defaultReturnUrl ( )
return string

Return URL.

                protected function defaultReturnUrl()
{
    $params = $_GET;
    unset($params['oauth_token']);
    $params[0] = Yii::$app->controller->getRoute();
    return Yii::$app->getUrlManager()->createAbsoluteUrl($params);
}

            
defaultTitle() protected method

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

Generates service title.

protected string defaultTitle ( )
return string

Service title.

                protected function defaultTitle()
{
    return StringHelper::basename(get_class($this));
}

            
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 [];
}

            
determineContentTypeByHeaders() protected method

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

Attempts to determine HTTP request content type by headers.

protected string determineContentTypeByHeaders ( array $headers )
$headers array

Request headers.

return string

Content type.

                protected function determineContentTypeByHeaders(array $headers)
{
    if (isset($headers['content_type'])) {
        if (stripos($headers['content_type'], 'json') !== false) {
            return self::CONTENT_TYPE_JSON;
        }
        if (stripos($headers['content_type'], 'urlencoded') !== false) {
            return self::CONTENT_TYPE_URLENCODED;
        }
        if (stripos($headers['content_type'], 'xml') !== false) {
            return self::CONTENT_TYPE_XML;
        }
    }
    return self::CONTENT_TYPE_AUTO;
}

            
determineContentTypeByRaw() protected method

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

Attempts to determine the content type from raw content.

protected string determineContentTypeByRaw ( $rawContent )
$rawContent string

Raw response content.

return string

Response type.

                protected function determineContentTypeByRaw($rawContent)
{
    if (preg_match('/^\\{.*\\}$/is', $rawContent)) {
        return self::CONTENT_TYPE_JSON;
    }
    if (preg_match('/^[^=|^&]+=[^=|^&]+(&[^=|^&]+=[^=|^&]+)*$/is', $rawContent)) {
        return self::CONTENT_TYPE_URLENCODED;
    }
    if (preg_match('/^<.*>$/is', $rawContent)) {
        return self::CONTENT_TYPE_XML;
    }
    return self::CONTENT_TYPE_AUTO;
}

            
fetchAccessToken() public method

Fetches OAuth access token.

public yii\authclient\OAuthToken fetchAccessToken ( yii\authclient\OAuthToken $requestToken null, $oauthVerifier null, array $params = [] )
$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\Exception

on failure.

                public function fetchAccessToken(OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
{
    if (!is_object($requestToken)) {
        $requestToken = $this->getState('requestToken');
        if (!is_object($requestToken)) {
            throw new Exception('Request token is required to fetch access token!');
        }
    }
    $this->removeState('requestToken');
    $defaultParams = [
        'oauth_consumer_key' => $this->consumerKey,
        'oauth_token' => $requestToken->getToken()
    ];
    if ($oauthVerifier === null) {
        if (isset($_REQUEST['oauth_verifier'])) {
            $oauthVerifier = $_REQUEST['oauth_verifier'];
        }
    }
    if (!empty($oauthVerifier)) {
        $defaultParams['oauth_verifier'] = $oauthVerifier;
    }
    $response = $this->sendSignedRequest($this->accessTokenMethod, $this->accessTokenUrl, array_merge($defaultParams, $params));
    $token = $this->createToken([
        'params' => $response
    ]);
    $this->setAccessToken($token);
    return $token;
}

            
fetchRequestToken() public method

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->removeState('token');
    $defaultParams = [
        'oauth_consumer_key' => $this->consumerKey,
        'oauth_callback' => $this->getReturnUrl(),
        //'xoauth_displayname' => Yii::$app->name,
    ];
    if (!empty($this->scope)) {
        $defaultParams['scope'] = $this->scope;
    }
    $response = $this->sendSignedRequest($this->requestTokenMethod, $this->requestTokenUrl, array_merge($defaultParams, $params));
    $token = $this->createToken([
        'params' => $response
    ]);
    $this->setState('requestToken', $token);
    return $token;
}

            
generateCommonRequestParams() protected method

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

Generates nonce value.

protected string generateNonce ( )
return string

Nonce value.

                protected function generateNonce()
{
    return md5(microtime() . mt_rand());
}

            
generateTimestamp() protected method

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;
}

            
getCurlOptions() public method
public array getCurlOptions ( )
return array

CURL options.

                public function getCurlOptions()
{
    return $this->_curlOptions;
}

            
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;
}

            
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\BaseOAuth::getState()

Returns persistent state value.

protected mixed getState ( $key )
$key string

State key.

return mixed

State value.

                protected function getState($key)
{
    if (!Yii::$app->has('session')) {
        return null;
    }
    /* @var \yii\web\Session $session */
    $session = Yii::$app->get('session');
    $key = $this->getStateKeyPrefix() . $key;
    $value = $session->get($key);
    return $value;
}

            
getStateKeyPrefix() protected method

Defined in: yii\authclient\BaseOAuth::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) . '_' . sha1($this->authUrl) . '_';
}

            
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;
}

            
initUserAttributes() protected method

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

Initializes authenticated user attributes.

protected array initUserAttributes ( )
return array

Auth user attributes.

                protected function initUserAttributes()
{
    throw new NotSupportedException('Method "' . get_class($this) . '::' . __FUNCTION__ . '" not implemented.');
}

            
mergeCurlOptions() protected method

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

Merge CUrl options.

If each options array has an element with the same key value, the latter will overwrite the former.

protected array mergeCurlOptions ( $options1, $options2 )
$options1 array

Options to be merged to.

$options2 array

Options to be merged from. You can specify additional arrays via third argument, fourth argument etc.

return array

Merged options (the original options are not changed.)

                protected function mergeCurlOptions($options1, $options2)
{
    $args = func_get_args();
    $res = array_shift($args);
    while (!empty($args)) {
        $next = array_shift($args);
        foreach ($next as $k => $v) {
            if (is_array($v) && !empty($res[$k]) && is_array($res[$k])) {
                $res[$k] = array_merge($res[$k], $v);
            } else {
                $res[$k] = $v;
            }
        }
    }
    return $res;
}

            
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;
}

            
processResponse() protected method

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

Processes raw response converting it to actual data.

protected array processResponse ( $rawResponse, $contentType self::CONTENT_TYPE_AUTO )
$rawResponse string

Raw response.

$contentType string

Response content type.

return array

Actual response.

throws \yii\base\Exception

on failure.

                protected function processResponse($rawResponse, $contentType = self::CONTENT_TYPE_AUTO)
{
    if (empty($rawResponse)) {
        return [];
    }
    switch ($contentType) {
        case self::CONTENT_TYPE_AUTO: {
            $contentType = $this->determineContentTypeByRaw($rawResponse);
            if ($contentType == self::CONTENT_TYPE_AUTO) {
                throw new Exception('Unable to determine response content type automatically.');
            }
            $response = $this->processResponse($rawResponse, $contentType);
            break;
        }
        case self::CONTENT_TYPE_JSON: {
            $response = Json::decode($rawResponse, true);
            break;
        }
        case self::CONTENT_TYPE_URLENCODED: {
            $response = [];
            parse_str($rawResponse, $response);
            break;
        }
        case self::CONTENT_TYPE_XML: {
            $response = $this->convertXmlToArray($rawResponse);
            break;
        }
        default: {
            throw new Exception('Unknown response type "' . $contentType . '".');
        }
    }
    return $response;
}

            
refreshAccessToken() public method

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\BaseOAuth::removeState()

Removes persistent state value.

protected boolean removeState ( $key )
$key string

State key.

return boolean

Success.

                protected function removeState($key)
{
    if (!Yii::$app->has('session')) {
        return true;
    }
    /* @var \yii\web\Session $session */
    $session = Yii::$app->get('session');
    $key = $this->getStateKeyPrefix() . $key;
    $session->remove($key);
    return true;
}

            
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 ( yii\authclient\OAuthToken $token )
$token yii\authclient\OAuthToken

Auth token

return $this

The object itself.

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

            
sendRequest() protected method

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

Sends HTTP request.

protected array sendRequest ( $method, $url, array $params = [], array $headers = [] )
$method string

Request type.

$url string

Request URL.

$params array

Request params.

$headers array

Additional request headers.

return array

Response.

throws \yii\base\Exception

on failure.

                protected function sendRequest($method, $url, array $params = [], array $headers = [])
{
    $curlOptions = $this->mergeCurlOptions(
        $this->defaultCurlOptions(),
        $this->getCurlOptions(),
        [
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_URL => $url,
        ],
        $this->composeRequestCurlOptions(strtoupper($method), $url, $params)
    );
    $curlResource = curl_init();
    foreach ($curlOptions as $option => $value) {
        curl_setopt($curlResource, $option, $value);
    }
    $response = curl_exec($curlResource);
    $responseHeaders = curl_getinfo($curlResource);
    // check cURL error
    $errorNumber = curl_errno($curlResource);
    $errorMessage = curl_error($curlResource);
    curl_close($curlResource);
    if ($errorNumber > 0) {
        throw new Exception('Curl error requesting "' .  $url . '": #' . $errorNumber . ' - ' . $errorMessage);
    }
    if (strncmp($responseHeaders['http_code'], '20', 2) !== 0) {
        throw new InvalidResponseException($responseHeaders, $response, 'Request failed with code: ' . $responseHeaders['http_code'] . ', message: ' . $response);
    }
    return $this->processResponse($response, $this->determineContentTypeByHeaders($responseHeaders));
}

            
sendSignedRequest() protected method

Sends HTTP request, signed by $signatureMethod.

protected array sendSignedRequest ( $method, $url, array $params = [], array $headers = [] )
$method string

Request type.

$url string

Request URL.

$params array

Request params.

$headers array

Additional request headers.

return array

Response.

                protected function sendSignedRequest($method, $url, array $params = [], array $headers = [])
{
    $params = array_merge($params, $this->generateCommonRequestParams());
    $params = $this->signRequest($method, $url, $params);
    return $this->sendRequest($method, $url, $params, $headers);
}

            
setAccessToken() public method
public void setAccessToken ( $token )
$token array|yii\authclient\OAuthToken

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

            
setCurlOptions() public method
public void setCurlOptions ( array $curlOptions )
$curlOptions array

CURL options.

                public function setCurlOptions(array $curlOptions)
{
    $this->_curlOptions = $curlOptions;
}

            
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;
}

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

Return URL

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

            
setSignatureMethod() public method
public void setSignatureMethod ( $signatureMethod )
$signatureMethod array|yii\authclient\signature\BaseMethod

Signature method instance or its array configuration.

throws \yii\base\InvalidParamException

on wrong argument.

                public function setSignatureMethod($signatureMethod)
{
    if (!is_object($signatureMethod) && !is_array($signatureMethod)) {
        throw new InvalidParamException('"' . 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\BaseOAuth::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)
{
    if (!Yii::$app->has('session')) {
        return $this;
    }
    /* @var \yii\web\Session $session */
    $session = Yii::$app->get('session');
    $key = $this->getStateKeyPrefix() . $key;
    $session->set($key, $value);
    return $this;
}

            
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() protected method

Sign request with $signatureMethod.

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

Request method.

$url string

Request URL.

$params array

Request params.

return array

Signed request params.

                protected function signRequest($method, $url, array $params)
{
    $signatureMethod = $this->getSignatureMethod();
    $params['oauth_signature_method'] = $signatureMethod->getName();
    $signatureBaseString = $this->composeSignatureBaseString($method, $url, $params);
    $signatureKey = $this->composeSignatureKey();
    $params['oauth_signature'] = $signatureMethod->generateSignature($signatureBaseString, $signatureKey);
    return $params;
}