0 follower

Final Class Yiisoft\Yii\AuthClient\OAuthToken

InheritanceYiisoft\Yii\AuthClient\OAuthToken

Token represents OAuth token.

Protected Methods

Hide inherited methods

Method Description Defined By
defaultExpireDurationParamKey() Fetches default expire duration param key. Yiisoft\Yii\AuthClient\OAuthToken

Method Details

Hide inherited methods

__construct() public method

public __construct( ): mixed

                public function __construct()
{
    $this->createTimestamp = time();
}

            
defaultExpireDurationParamKey() protected method

Fetches default expire duration param key.

protected defaultExpireDurationParamKey( ): string
return string

Expire duration param key.

                protected function defaultExpireDurationParamKey(): string
{
    $expireDurationParamKey = 'expires_in';
    /**
     * @var mixed $value
     */
    foreach ($this->getParams() as $name => $value) {
        if (!str_contains((string)$name, 'expir')) {
        } else {
            $expireDurationParamKey = (string)$name;
            break;
        }
    }
    return $expireDurationParamKey;
}

            
getExpireDuration() public method

Returns the token expiration duration.

return mixed token expiration duration.

public getExpireDuration( ): mixed

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

            
getExpireDurationParamKey() public method

public getExpireDurationParamKey( ): string
return string

Expire duration param key.

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

            
getIsExpired() public method

Checks if token has expired.

public getIsExpired( ): boolean
return boolean

Is token expired.

                public function getIsExpired(): bool
{
    $expirationDuration = (int)$this->getExpireDuration();
    return time() >= ($this->createTimestamp + $expirationDuration);
}

            
getIsValid() public method

Checks if token is valid.

public getIsValid( ): boolean
return boolean

Is token valid.

                public function getIsValid(): bool
{
    $token = $this->getToken();
    return strlen($token ?? '') > 0 && !$this->getIsExpired();
}

            
getParam() public method

Returns param by name.

public getParam( string $name ): mixed
$name string

Param name.

return mixed

Param value.

                public function getParam(string $name): mixed
{
    return $this->params[$name] ?? null;
}

            
getParams() public method

public getParams( ): array

                public function getParams(): array
{
    return $this->params;
}

            
getToken() public method

Returns token value.

public getToken( ): string|null

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

            
getTokenSecret() public method

Returns the token secret value.

public getTokenSecret( ): string
return string

Token secret value.

                public function getTokenSecret(): string
{
    return $this->getParam($this->tokenSecretParamKey ?: 'oauth_token_secret');
}

            
setExpireDuration() public method

Sets token expire duration.

public setExpireDuration( integer $expireDuration ): void
$expireDuration integer

Token expiration duration.

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

            
setParam() public method

Sets param by name.

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

Param name.

$value mixed

Param value,

                public function setParam(string $name, mixed $value): void
{
    $this->params[$name] = $value;
}

            
setParams() public method

public setParams( array $params ): void
$params array

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

            
setToken() public method

Sets token value.

public setToken( string $token ): void
$token string

Token value.

                public function setToken(string $token): void
{
    $this->setParam($this->tokenParamKey ?: 'oauth_token', $token);
}

            
setTokenSecret() public method

Sets the token secret value.

public setTokenSecret( string $tokenSecret ): void
$tokenSecret string

Token secret.

                public function setTokenSecret(string $tokenSecret): void
{
    $this->setParam($this->tokenSecretParamKey ?: 'oauth_token_secret', $tokenSecret);
}