Class yii\authclient\OAuthToken

Inheritanceyii\authclient\OAuthToken » yii\base\BaseObject
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/src/OAuthToken.php

Token represents OAuth token.

Public Properties

Hide inherited properties

Property Type Description Defined By
$createTimestamp integer Object creation timestamp. yii\authclient\OAuthToken
$expireDuration integer Token expiration duration. yii\authclient\OAuthToken
$expireDurationParamKey string Expire duration param key. yii\authclient\OAuthToken
$isExpired boolean Is token expired. yii\authclient\OAuthToken
$isValid boolean Is token valid. yii\authclient\OAuthToken
$params array This property is read-only. yii\authclient\OAuthToken
$token string Token value. yii\authclient\OAuthToken
$tokenParamKey string Key in $params array, which stores token key. yii\authclient\OAuthToken
$tokenSecret string Token secret value. yii\authclient\OAuthToken
$tokenSecretParamKey string Key in $params array, which stores token secret key. yii\authclient\OAuthToken

Protected Methods

Hide inherited methods

Method Description Defined By
defaultExpireDurationParamKey() Fetches default expire duration param key. yii\authclient\OAuthToken

Property Details

Hide inherited properties

$createTimestamp public property

Object creation timestamp.

public integer $createTimestamp null
$expireDuration public property

Token expiration duration. Note that the type of this property differs in getter and setter. See getExpireDuration() and setExpireDuration() for details.

public integer $expireDuration null
$expireDurationParamKey public property

Expire duration param key.

$isExpired public property

Is token expired. This property is read-only.

public boolean $isExpired null
$isValid public property

Is token valid. This property is read-only.

public boolean $isValid null
$params public property

This property is read-only.

public array $params null
$token public property

Token value.

public string $token null
$tokenParamKey public property

Key in $params array, which stores token key.

public string $tokenParamKey 'oauth_token'
$tokenSecret public property

Token secret value.

public string $tokenSecret null
$tokenSecretParamKey public property

Key in $params array, which stores token secret key.

public string $tokenSecretParamKey 'oauth_token_secret'

Method Details

Hide inherited methods

defaultExpireDurationParamKey() protected method

Fetches default expire duration param key.

protected string defaultExpireDurationParamKey ( )
return string

Expire duration param key.

                protected function defaultExpireDurationParamKey()
{
    $expireDurationParamKey = 'expires_in';
    foreach ($this->getParams() as $name => $value) {
        if (strpos($name, 'expir') !== false) {
            $expireDurationParamKey = $name;
            break;
        }
    }
    return $expireDurationParamKey;
}

            
getExpireDuration() public method

Returns the token expiration duration.

public integer getExpireDuration ( )
return integer

Token expiration duration.

                public function getExpireDuration()
{
    return $this->getParam($this->getExpireDurationParamKey());
}

            
getExpireDurationParamKey() public method

public string getExpireDurationParamKey ( )
return string

Expire duration param key.

                public function getExpireDurationParamKey()
{
    if ($this->_expireDurationParamKey === null) {
        $this->_expireDurationParamKey = $this->defaultExpireDurationParamKey();
    }
    return $this->_expireDurationParamKey;
}

            
getIsExpired() public method

Checks if token has expired.

public boolean getIsExpired ( )
return boolean

Is token expired.

                public function getIsExpired()
{
    $expirationDuration = $this->getExpireDuration();
    if (empty($expirationDuration)) {
        return false;
    }
    return (time() >= ($this->createTimestamp + $expirationDuration));
}

            
getIsValid() public method

Checks if token is valid.

public boolean getIsValid ( )
return boolean

Is token valid.

                public function getIsValid()
{
    $token = $this->getToken();
    return (!empty($token) && !$this->getIsExpired());
}

            
getParam() public method

Returns param by name.

public mixed getParam ( $name )
$name string

Param name.

return mixed

Param value.

                public function getParam($name)
{
    return isset($this->_params[$name]) ? $this->_params[$name] : null;
}

            
getParams() public method

public array getParams ( )

                public function getParams()
{
    return $this->_params;
}

            
getToken() public method

Returns token value.

public string getToken ( )
return string

Token value.

                public function getToken()
{
    return $this->getParam($this->tokenParamKey);
}

            
getTokenSecret() public method

Returns the token secret value.

public string getTokenSecret ( )
return string

Token secret value.

                public function getTokenSecret()
{
    return $this->getParam($this->tokenSecretParamKey);
}

            
init() public method

public void init ( )

                public function init()
{
    if ($this->createTimestamp === null) {
        $this->createTimestamp = time();
    }
}

            
setExpireDuration() public method

Sets token expire duration.

public void setExpireDuration ( $expireDuration )
$expireDuration string

Token expiration duration.

                public function setExpireDuration($expireDuration)
{
    $this->setParam($this->getExpireDurationParamKey(), $expireDuration);
}

            
setExpireDurationParamKey() public method

public void setExpireDurationParamKey ( $expireDurationParamKey )
$expireDurationParamKey string

Expire duration param key.

                public function setExpireDurationParamKey($expireDurationParamKey)
{
    $this->_expireDurationParamKey = $expireDurationParamKey;
}

            
setParam() public method

Sets param by name.

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

Param name.

$value mixed

Param value,

                public function setParam($name, $value)
{
    $this->_params[$name] = $value;
}

            
setParams() public method

public void setParams ( array $params )
$params array

                public function setParams(array $params)
{
    $this->_params = $params;
}

            
setToken() public method

Sets token value.

public $this setToken ( $token )
$token string

Token value.

return $this

The object itself

                public function setToken($token)
{
    $this->setParam($this->tokenParamKey, $token);
}

            
setTokenSecret() public method

Sets the token secret value.

public void setTokenSecret ( $tokenSecret )
$tokenSecret string

Token secret.

                public function setTokenSecret($tokenSecret)
{
    $this->setParam($this->tokenSecretParamKey, $tokenSecret);
}