Class yii\authclient\OAuthToken
| Inheritance | yii\authclient\OAuthToken » yii\base\Object |
|---|---|
| Available since extension's version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/OAuthToken.php |
Token represents OAuth token.
Public 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 |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| getExpireDuration() | Returns the token expiration duration. | yii\authclient\OAuthToken |
| getExpireDurationParamKey() | yii\authclient\OAuthToken | |
| getIsExpired() | Checks if token has expired. | yii\authclient\OAuthToken |
| getIsValid() | Checks if token is valid. | yii\authclient\OAuthToken |
| getParam() | Returns param by name. | yii\authclient\OAuthToken |
| getParams() | yii\authclient\OAuthToken | |
| getToken() | Returns token value. | yii\authclient\OAuthToken |
| getTokenSecret() | Returns the token secret value. | yii\authclient\OAuthToken |
| init() | yii\authclient\OAuthToken | |
| setExpireDuration() | Sets token expire duration. | yii\authclient\OAuthToken |
| setExpireDurationParamKey() | yii\authclient\OAuthToken | |
| setParam() | Sets param by name. | yii\authclient\OAuthToken |
| setParams() | yii\authclient\OAuthToken | |
| setToken() | Sets token value. | yii\authclient\OAuthToken |
| setTokenSecret() | Sets the token secret value. | yii\authclient\OAuthToken |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| defaultExpireDurationParamKey() | Fetches default expire duration param key. | yii\authclient\OAuthToken |
Property Details
Token expiration duration. Note that the type of this property differs in getter and setter. See getExpireDuration() and setExpireDuration() for details.
Expire duration param key.
Is token expired. This property is read-only.
Key in $params array, which stores token key.
Key in $params array, which stores token secret key.
Method Details
Fetches default expire duration param key.
| protected defaultExpireDurationParamKey( ): string | ||
| 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 getExpireDuration( ): integer | ||
| return | integer |
Token expiration duration. |
|---|---|---|
public function getExpireDuration()
{
return $this->getParam($this->getExpireDurationParamKey());
}
| public getExpireDurationParamKey( ): string | ||
| 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 getIsExpired( ): boolean | ||
| 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 getIsValid( ): boolean | ||
| return | boolean |
Is token valid. |
|---|---|---|
public function getIsValid()
{
$token = $this->getToken();
return (!empty($token) && !$this->getIsExpired());
}
Returns param by name.
| public getParam( string $name ): mixed | ||
| $name | string |
Param name. |
| return | mixed |
Param value. |
|---|---|---|
public function getParam($name)
{
return isset($this->_params[$name]) ? $this->_params[$name] : null;
}
Returns token value.
| public getToken( ): string | ||
| return | string |
Token value. |
|---|---|---|
public function getToken()
{
return $this->getParam($this->tokenParamKey);
}
Returns the token secret value.
| public getTokenSecret( ): string | ||
| return | string |
Token secret value. |
|---|---|---|
public function getTokenSecret()
{
return $this->getParam($this->tokenSecretParamKey);
}
| public init( ): |
public function init()
{
if ($this->createTimestamp === null) {
$this->createTimestamp = time();
}
}
Sets token expire duration.
| public setExpireDuration( string $expireDuration ): mixed | ||
| $expireDuration | string |
Token expiration duration. |
public function setExpireDuration($expireDuration)
{
$this->setParam($this->getExpireDurationParamKey(), $expireDuration);
}
| public setExpireDurationParamKey( string $expireDurationParamKey ): mixed | ||
| $expireDurationParamKey | string |
Expire duration param key. |
public function setExpireDurationParamKey($expireDurationParamKey)
{
$this->_expireDurationParamKey = $expireDurationParamKey;
}
Sets param by name.
| public setParam( string $name, mixed $value ): mixed | ||
| $name | string |
Param name. |
| $value | mixed |
Param value, |
public function setParam($name, $value)
{
$this->_params[$name] = $value;
}
| public setParams( array $params ): mixed | ||
| $params | array | |
public function setParams(array $params)
{
$this->_params = $params;
}
Sets token value.
| public setToken( string $token ): $this | ||
| $token | string |
Token value. |
| return | $this |
The object itself |
|---|---|---|
public function setToken($token)
{
$this->setParam($this->tokenParamKey, $token);
}
Sets the token secret value.
| public setTokenSecret( string $tokenSecret ): mixed | ||
| $tokenSecret | string |
Token secret. |
public function setTokenSecret($tokenSecret)
{
$this->setParam($this->tokenSecretParamKey, $tokenSecret);
}