Class yii\authclient\OAuthToken
| Inheritance | yii\ |
|---|---|
| Available since extension's version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/src/OAuthToken.php |
Token represents OAuth token.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $createTimestamp | integer | Object creation timestamp. | yii\ |
| $expireDuration | string | Token expiration duration. | yii\ |
| $expireDurationParamKey | string | Expire duration param key. | yii\ |
| $isExpired | boolean | Is token expired. | yii\ |
| $isValid | boolean | Is token valid. | yii\ |
| $params | array | yii\ |
|
| $refreshToken | string | yii\ |
|
| $refreshTokenParamKey | string | Key in $params array, which stores refresh token key. | yii\ |
| $token | string | Token value. | yii\ |
| $tokenParamKey | string | Key in $params array, which stores token key. | yii\ |
| $tokenSecret | string | Token secret value. | yii\ |
| $tokenSecretParamKey | string | Key in $params array, which stores token secret key. | yii\ |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| defaultExpireDurationParamKey() | Fetches default expire duration param key. | yii\ |
Property Details
Expire duration param key.
Key in $params array, which stores refresh token key.
Key in $params array, which stores token key.
Key in $params array, which stores token secret key.
Method Details
| public mixed __construct ( array $config = [] ) | ||
| $config | array | |
public function __construct(array $config = [])
{
if (array_key_exists('tokenParamKey', $config)) {
$this->tokenParamKey = ArrayHelper::remove($config, 'tokenParamKey');
}
if (array_key_exists('tokenSecretParamKey', $config)) {
$this->tokenSecretParamKey = ArrayHelper::remove($config, 'tokenSecretParamKey');
}
if (array_key_exists('refreshTokenParamKey', $config)) {
$this->refreshTokenParamKey = ArrayHelper::remove($config, 'refreshTokenParamKey');
}
parent::__construct($config);
}
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;
}
Returns the token expiration duration.
| public integer getExpireDuration ( ) | ||
| return | integer |
Token expiration duration. |
|---|---|---|
public function getExpireDuration()
{
return $this->getParam($this->getExpireDurationParamKey());
}
| public string getExpireDurationParamKey ( ) | ||
| return | string |
Expire duration param key. |
|---|---|---|
public function getExpireDurationParamKey()
{
if ($this->_expireDurationParamKey === null) {
$this->_expireDurationParamKey = $this->defaultExpireDurationParamKey();
}
return $this->_expireDurationParamKey;
}
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));
}
Checks if token is valid.
| public boolean getIsValid ( ) | ||
| return | boolean |
Is token valid. |
|---|---|---|
public function getIsValid()
{
$token = $this->getToken();
return (!empty($token) && !$this->getIsExpired());
}
Returns param by name.
| public mixed getParam ( string $name ) | ||
| $name | string |
Param name. |
| return | mixed |
Param value. |
|---|---|---|
public function getParam($name)
{
return isset($this->_params[$name]) ? $this->_params[$name] : null;
}
| public mixed getRefreshToken ( ) |
public function getRefreshToken()
{
return $this->getParam($this->refreshTokenParamKey);
}
Returns token value.
| public string getToken ( ) | ||
| return | string |
Token value. |
|---|---|---|
public function getToken()
{
return $this->getParam($this->tokenParamKey);
}
Returns the token secret value.
| public string getTokenSecret ( ) | ||
| return | string |
Token secret value. |
|---|---|---|
public function getTokenSecret()
{
return $this->getParam($this->tokenSecretParamKey);
}
| public mixed hasRefreshToken ( ) |
public function hasRefreshToken()
{
return !!$this->getRefreshToken();
}
| public init ( ) |
public function init()
{
if ($this->createTimestamp === null) {
$this->createTimestamp = time();
}
}
Sets token expire duration.
| public mixed setExpireDuration ( string $expireDuration ) | ||
| $expireDuration | string |
Token expiration duration. |
public function setExpireDuration($expireDuration)
{
$this->setParam($this->getExpireDurationParamKey(), $expireDuration);
}
| public mixed setExpireDurationParamKey ( string $expireDurationParamKey ) | ||
| $expireDurationParamKey | string |
Expire duration param key. |
public function setExpireDurationParamKey($expireDurationParamKey)
{
$this->_expireDurationParamKey = $expireDurationParamKey;
}
Sets param by name.
| public mixed setParam ( string $name, mixed $value ) | ||
| $name | string |
Param name. |
| $value | mixed |
Param value, |
public function setParam($name, $value)
{
$this->_params[$name] = $value;
}
| public mixed setParams ( array $params ) | ||
| $params | array | |
public function setParams(array $params)
{
$this->_params = $params;
}
Sets refresh token.
| public mixed setRefreshToken ( string $refreshToken ) | ||
| $refreshToken | string | |
public function setRefreshToken($refreshToken)
{
$this->setParam($this->refreshTokenParamKey, $refreshToken);
}
Sets token value.
| public $this setToken ( string $token ) | ||
| $token | string |
Token value. |
| return | $this |
The object itself |
|---|---|---|
public function setToken($token)
{
$this->setParam($this->tokenParamKey, $token);
}
Sets the token secret value.
| public mixed setTokenSecret ( string $tokenSecret ) | ||
| $tokenSecret | string |
Token secret. |
public function setTokenSecret($tokenSecret)
{
$this->setParam($this->tokenSecretParamKey, $tokenSecret);
}