Puts the given access token to the local cache

@param AccessToken $accessToken
179640
private function cacheToken(AccessToken $accessToken)
    {
        $tz = self::TIME_ZONE;
        $kvs = $this->getKeyValueStorage();

        $liveTimeInSec = Carbon::createFromTimestamp($accessToken->getExpires(), $tz)->diffInSeconds(Carbon::now($tz));

        $kvs->set(self::ACCESS_TOKEN_KEY, $accessToken->getToken());
        $kvs->expire(self::ACCESS_TOKEN_KEY, $liveTimeInSec);
        $kvs->set(self::REFRESH_TOKEN_KEY, $accessToken->getRefreshToken());
    }
891286
public function deleteAccessToken($userId, AccessToken $accessToken)
    {
        $stmt = $this->db->prepare(
            'DELETE FROM
                access_tokens
            WHERE
                user_id = :user_id
            AND
                provider_id = :provider_id
            AND
                access_token = :access_token'
        );

        $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR);
        $stmt->bindValue(':provider_id', $accessToken->getProviderId(), PDO::PARAM_STR);
        $stmt->bindValue(':access_token', $accessToken->getToken(), PDO::PARAM_STR);
        $stmt->execute();
    }
426029
public function setAccessTokenCacheFile($accessTokenCacheFile)
	{
		if (is_dir($accessTokenCacheFile))
			$accessTokenCacheFile .= DIRECTORY_SEPARATOR;

		$this->accessTokenCacheFile = $accessTokenCacheFile;

		return $this;
	}
217651
public function addAccessLevel(AccessLevel $accessLevel)
    {
        // Add the access level
        $this->accessLevels[$accessLevel->getKey()] = $accessLevel;
        
        // Save the access levels
        $this->saveAccessLevels();
    }
909473
public function setAccessToken(AccessToken $accessToken)
    {
        if (!$accessToken->isValid()) {
            $accessToken->refresh();
        }

        $this->accessToken = $accessToken;
    }
257223
public function setAccessToken($accessToken)
    {
        if (in_array('access_token', $this->persistantMap)) {
            $this->store->set('access_token', $accessToken);
        }

        $this->accessToken = $accessToken;
        return $this;
    }
1329233
public function setAccessTokenFromParams($accessToken)
    {
        $existingAccessToken = $this->getAccessToken();
        if (!$existingAccessToken) {
            $this->setAccessToken($accessToken);
        } elseif ($accessToken !== $existingAccessToken) {
            throw new SteeinSDKException('Ошибка доступа к токенам. Токен доступа, указанный в запросе SteeinRequest, и токен, указанный в параметрах URL или POST, не совпадают.');
        }

        return $this;
    }
84930
public function setAccessToken(AccessToken $accessToken)
    {
        $this->accessToken = $accessToken;

        if ($this->tokenUpdatedCallback) {
            call_user_func($this->tokenUpdatedCallback, $accessToken);
        }
    }
1228606
public function setAccessToken(AccessToken $token)
    {
        $this->container->get('config')
            ->set('access_token', json_encode($token->jsonSerialize()));
    }
733030
public function setCache($file)
	{
		if ( ! empty($file)) {
			$this->cache = new AccessTokenCache($file);

			$this->setAccessToken($this->cache->get());
		}
	}
233151
public function setAccessToken($token)
    {
        if (is_string($token)) {
            $token = new Token($token);
        }
        Requestor::setToken($token);
    }
342663
private function setExpiresIn($expiresIn)
    {
        if (null !== $expiresIn) {
            if (false === \is_int($expiresIn)) {
                throw new AccessTokenException('"expires_in" must be int');
            }
            if (0 >= $expiresIn) {
                throw new AccessTokenException('invalid "expires_in"');
            }
        }
        $this->expiresIn = $expiresIn;
    }
268566
protected function store_token($token) {
        if (!$this->system) {
            parent::store_token($token);
            return;
        }

        $this->accesstoken = $token;

        // Create or update a DB record with the new token.
        $persistedtoken = access_token::get_record(['issuerid' => $this->issuer->get('id')]);
        if ($token !== null) {
            if (!$persistedtoken) {
                $persistedtoken = new access_token();
                $persistedtoken->set('issuerid', $this->issuer->get('id'));
            }
            // Update values from $token. Don't use from_record because that would skip validation.
            $persistedtoken->set('token', $token->token);
            if (isset($token->expires)) {
                $persistedtoken->set('expires', $token->expires);
            } else {
                // Assume an arbitrary time span of 1 week for access tokens without expiration.
                // The "refresh_system_tokens_task" is run hourly (by default), so the token probably won't last that long.
                $persistedtoken->set('expires', time() + WEEKSECS);
            }
            $persistedtoken->set('scope', $token->scope);
            $persistedtoken->save();
        } else {
            if ($persistedtoken) {
                $persistedtoken->delete();
            }
        }
    }
257235
public static function refreshToken(AccessToken $token, $params = null)
    {
        if ($token->expires_at > new \DateTime()) {
            return $token;
        }

        $requestor = new ApiRequestor(Sumup::$connectBase, true);
        $params = [
            'grant_type' => 'refresh_token',
            'client_id' => self::_getConnectParam('client_id', $params),
            'client_secret' => self::_getConnectParam('client_secret', $params),
            'refresh_token' => $token->refresh_token
        ];
        $response = $requestor->request('post', '/token', $params);

        if ($response->raw->getStatusCode() !== 200) {
            throw new Error\AuthenticationError('Token request error');
        }

        return new AccessToken($response);
    }
226783
public function create($token, $expireTime, $accessToken)
    {
        $this->getConnection()->table('oauth_refresh_tokens')->insert([
            'id' => $token,
            'expire_time' => $expireTime,
            'access_token_id' => $accessToken,
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now(),
        ]);

        return (new RefreshTokenEntity($this->getServer()))
               ->setId($token)
               ->setAccessTokenId($accessToken)
               ->setExpireTime((int) $expireTime);
    }
757389
public function setAccessToken(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\AccessToken $accessToken = null)
    {
        $this->access_token = $accessToken;

        return $this;
    }
534464
public function handleRefreshToken(AccessToken $previousToken, int $tries): AccessToken
    {
        return $this->client->getConfiguration()->refreshToken($previousToken->getRefreshToken());
    }