@param ApiClientInterface $client
@param string $refreshToken

@return TokenInterface
343616
public function findOneByClientAndRefreshToken(ApiClientInterface $client, $refreshToken)
    {
        $qb = $this->createQueryBuilder();

        $qb->field('client.id')->equals($client->getId());
        $qb->field('refreshCode')->equals($refreshToken);
        $qb->limit(1);

        return $qb->getQuery()->getSingleResult();
    }
706627
protected function prepareTokenResponse(
        AccessToken $accessToken,
        RefreshToken $refreshToken = null,
        bool $useRefreshTokenScopes = false
    ): ResponseInterface {
        $owner = $accessToken->getOwner();
        $scopes = $useRefreshTokenScopes ? $refreshToken->getScopes() : $accessToken->getScopes();

        $responseBody = [
            'access_token' => $accessToken->getToken(),
            'token_type' => 'Bearer',
            'expires_in' => $accessToken->getExpiresIn(),
            'scope' => implode(' ', $scopes),
            'owner_id' => $owner ? $owner->getTokenOwnerId() : null,
        ];

        if (null !== $refreshToken) {
            $responseBody['refresh_token'] = $refreshToken->getToken();
        }

        return new Response\JsonResponse(array_filter($responseBody));
    }
128705
public function refreshAccessToken(TokenInterface $token)
    {
      $refreshToken = $token->getRefreshToken();

      if(empty($refreshToken))
        throw new MissingRefreshTokenException();

      $parameters = array(
        'grant_type'    => 'refresh_token',
        'type'          => 'web_server',
        'client_id'     => $this->credentials->getConsumerId(),
        'client_secret' => $this->credentials->getConsumerSecret(),
        'refresh_token' => $refreshToken,
      );

      require_once 'libx/base.php';

      require_once 'libx/net/http/codes.class.php';
      require_once 'libx/net/rest/client.class.php';
      require_once 'libx/net/rest/request.class.php';
      require_once 'libx/net/rest/response.class.php';

      $request = new \LibXRestRequest($this->getAccessTokenEndpoint(), \LibXRestRequest::REQUEST_METHOD_POST);
      $request->setParameters($parameters);

      $response = new \LibXRestResponse();

      $client = new \LibXRestClient();
      $client->execute($request, $response);

      // Parse token
      $token = $this->parseAccessToken($response->getData());

      // Store token
      $this->storage->storeAccessToken($this->service(), $token);

      // Return token
      return $token;
    }
1228269
public function handle(ClientRepository $clients)
    {
        $count = DB::table('oauth_refresh_tokens')->where('expires_at', '<', new DateTime())->delete();

        if (Passport::$refreshTokensExpireAt && Passport::$tokensExpireAt) {
            $difference = Passport::$refreshTokensExpireAt->getTimestamp() - Passport::$tokensExpireAt->getTimestamp();

            // We assume it's safe to delete tokens that cannot be refreshed anyway
            $count += DB::table('oauth_access_tokens')
                ->where('expires_at', '<', (new DateTime())->setTimestamp(time() - $difference))
                ->delete();
        }

        $this->info('Successfully deleted expired tokens: ' . $count);
    }
1281726
public function setRefreshToken($refresh_token)
    {
        $key = array_search('refresh_token', $this->persistantMap);
        if ($key !== false) {
            $this->store->set('refresh_token', $refresh_token);
        }

        $this->refresh_token = $refresh_token;

        return $this;
    }
5074
private function setRefreshToken($refreshToken)
    {
        if (null !== $refreshToken) {
            // refresh-token = 1*VSCHAR
            // VSCHAR        = %x20-7E
            if (1 !== \preg_match('/^[\x20-\x7E]+$/', $refreshToken)) {
                throw new AccessTokenException('invalid "refresh_token"');
            }
        }
        $this->refreshToken = $refreshToken;
    }
673413
protected function refreshIssueToken(array $parameters, ?ClientInterface $determinedClient): ResponseInterface
    {
        if (($refreshValue = $this->refreshGetValue($parameters)) === null) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_REQUEST);
        }

        if (($token = $this->refreshGetIntegration()->readTokenByRefreshValue($refreshValue)) === null) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_GRANT);
        }

        $clientIdFromToken = $token->getClientIdentifier();
        if ($determinedClient === null) {
            $isClientFromToken = true;
            $determinedClient  = $this->refreshGetIntegration()->readClientByIdentifier($clientIdFromToken);
        } else {
            $isClientFromToken = false;
        }

        // if client didn't provided authentication (but had to) or
        // client associated with the token do not match provided client credentials we throw an exception
        if (($isClientFromToken === true &&
                ($determinedClient->isConfidential() === true || $determinedClient->hasCredentials() === true)) ||
            $determinedClient->getIdentifier() !== $clientIdFromToken
        ) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_CLIENT);
        }

        if ($determinedClient->isRefreshGrantEnabled() === false) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_UNAUTHORIZED_CLIENT);
        }

        $isScopeModified = false;
        $scopeList       = null;
        if (($requestedScope = $this->refreshGetScope($parameters)) !== null) {
            // check requested scope is within the current one
            if (empty(array_diff($requestedScope, $token->getScopeIdentifiers())) === false) {
                throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_SCOPE);
            }
            $isScopeModified = true;
            $scopeList       = $requestedScope;
        }

        $response = $this->refreshGetIntegration()->refreshCreateAccessTokenResponse(
            $determinedClient,
            $token,
            $isScopeModified,
            $scopeList,
            $parameters
        );

        return $response;
    }
342971
function refreshToken($accessToken, $sessionHandle) {
		$code = $this->request ( 'GET', $this->url ( 'AccessToken', '' ), array (
				'oauth_token' => $accessToken,
				'oauth_session_handle' => $sessionHandle 
		) );
		if ($this->response ['code'] == 200) {
			
			$response = $this->extract_params ( $this->response ['response'] );
			
			return $response;
		} else {
			$this->response ['helper'] = "TokenFatal";
			return $this->response;
		}
	}
769845
private function refreshToken(\Google_Client $client): bool
    {
        $accessToken = $client->getAccessToken();
        $data = \json_decode($accessToken, true);

        try {
            if (isset($data['refresh_token'])) {
                $client->refreshToken($data['refresh_token']);

                return true;
            }
        } catch (\Google_Auth_Exception $e) {
        }

        return false;
    }
954460
public function readByRefresh(string $refreshValue, int $expirationInSeconds): ?TokenInterface
    {
        $schema = $this->getDatabaseSchema();
        return $this->readEnabledTokenByColumnWithExpirationCheck(
            $refreshValue,
            $schema->getTokensRefreshColumn(),
            $expirationInSeconds,
            $schema->getTokensRefreshCreatedAtColumn()
        );
    }
1309663
protected function getRefreshToken($refreshToken)
    {
        if (null === $token = $this->app['repo.api-oauth-refresh-token']->find($refreshToken)) {
            return null;
        }

        return [
            'token'     => $token->getRefreshToken(),
            'expires'   => $token->getExpires(),
            'client_id' => $token->getAccount()->getApplication()->getClientId()
        ];
    }
1349930
protected function expireRefreshToken($refreshToken, $user)
    {
        $token = $this->refreshTokenMapper->findBy([
            'refresh_token' => $refreshToken,
            'user_id'       => $user->getId(),
        ]);

        if (! $token) {
            throw new OutOfBoundsException('Refresh token not found.');
        }

        $token->setExpires(date("Y-m-d H:i:s", time()));

        $this->refreshTokenMapper->update($token);
    }
1316526
public function refreshAccessToken(TokenInterface $token)
    {
        $refreshToken = $token->getRefreshToken();

        if (empty($refreshToken)) {
            throw new MissingRefreshTokenException();
        }

        $parameters = [
            'grant_type'    => 'refresh_token',
            'type'          => 'web_server',
            'client_id'     => $this->credentials->getConsumerId(),
            'client_secret' => $this->credentials->getConsumerSecret(),
            'refresh_token' => $refreshToken,
        ];

        $responseBody = $this->httpRequest(
            $this->getAccessTokenEndpoint(),
            $parameters,
            $this->getExtraOAuthHeaders()
        );
        $token = $this->parseAccessTokenResponse($responseBody);
        $this->storage->storeAccessToken($this->service(), $token);

        return $token;
    }
1119682
public function refreshToken($refreshToken)
	{
		$response = $this->http->get($this->getUrl('action/openapi/token'), array(
			'client_id'		=>	$this->appid,
			'client_secret'	=>	$this->appSecret,
			'grant_type'	=>	'refresh_token',
			'redirect_uri'	=>	$this->getRedirectUri(),
			'refresh_token'	=>	$refreshToken,
			'dataType'		=>	'json',
		));
		$this->result = $response->json(true);
		if(!isset($this->result['error']))
		{
			return $this->accessToken = $this->result['access_token'];
		}
		else
		{
			throw new ApiException(isset($this->result['error_description']) ? $this->result['error_description'] : '', $response->httpCode());
		}
	}
853632
public function createToken($owner, $client, array $scopes = []): RefreshToken
    {
        if (empty($scopes)) {
            $scopes = $this->scopeService->getDefaultScopes();
        } else {
            $this->validateTokenScopes($scopes);
        }

        do {
            $token = RefreshToken::createNewRefreshToken(
                $this->serverOptions->getRefreshTokenTtl(),
                $owner,
                $client,
                $scopes
            );
        } while ($this->tokenRepository->tokenExists($token->getToken()));

        return $this->tokenRepository->save($token);
    }
761955
private function getToken(Client $client, $forceNew = false)
    {
        $tokenName = sprintf('keystone_token_%s', rawurlencode($client->getTokenUrl()));

        // see if token is in cache
        if (!$forceNew && $cachedToken = $this->cache->get($tokenName)) {
            $token = unserialize($cachedToken);
        }

        if (!isset($token) || !($token instanceof Token) || $this->tokenIsExpired($token)) {
            $token = $this->createToken($client);
            $this->cache->set($tokenName, serialize($token), $token->getExpirationDate()->getTimestamp() - time());
        }

        return $token;
    }
558966
public function getToken($refresh = false)
    {
        if ($refresh || empty($this->_token)) {
            $data = ['grant_type' => 'client_credentials'];
            $this->_token = $this->_request(self::URN_ISSUE, $data);

            // check for valid response
            if (empty($this->_token->access_token)) {
                throw new AuthException('Unexpected empty token from the authentication server');
            }
        }
        return $this->_token;
    }