Refresh an access token.

@param string $refreshToken The refresh token to use.

@return bool Whether the access token was successfully refreshed.
436309
public function refreshAccessToken($refreshToken)
    {
        $payload = base64_encode($this->getClientId() . ':' . $this->getClientSecret());

        $parameters = [
            'grant_type' => 'refresh_token',
            'refresh_token' => $refreshToken,
        ];

        $headers = [
            'Authorization' => 'Basic ' . $payload,
        ];

        $response = $this->request->account('POST', '/api/token', $parameters, $headers);
        $response = $response['body'];

        if (isset($response->access_token)) {
            $this->accessToken = $response->access_token;
            $this->expirationTime = time() + $response->expires_in;
            $this->scope = isset($response->scope) ? $response->scope : $this->scope;

            if (isset($response->refresh_token)) {
                $this->refreshToken = $response->refresh_token;
            } elseif (empty($this->refreshToken)) {
                $this->refreshToken = $refreshToken;
            }

            return true;
        }

        return false;
    }
78046
public function refreshToken($accessToken = null)
    {
        $accessToken = $accessToken ?: $this->accessToken;
        $this->accessToken = $this->provider->getAccessToken('refresh_token', [
            'refresh_token' => $accessToken->getRefreshToken()
        ]);
        return $this->accessToken;
    }
4977
public function getRefreshToken($refresh_token)
    {
        return isset($this->refreshTokens[$refresh_token]) ? $this->refreshTokens[$refresh_token] : null;
    }
747633
protected function refreshAccessTokenIfRequired(): bool
    {
        if (!$this->client->isAccessTokenExpired()) {
            return false;
        }

        $this->logger->info('The access token is expired; refreshing the token');

        try {
            $accessToken = $this->client->fetchAccessTokenWithRefreshToken();
        } catch (\Exception $exception) {
            throw new \RuntimeException('Failed to refresh the token: '.$exception->getMessage());
        }
        if (isset($accessToken['error'])) {
            throw new \RuntimeException('Google has declined refreshing the token: '.($accessToken['error_description'] ?? '(no message)'));
        }

        return true;
    }
1303390
public function getAccess($code, $refreshToken = false)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        //populate fields
        $query = array(
            'client_id'         => $this->client,
            'client_secret'     => $this->secret,
            'redirect_uri'  => $this->redirect,
            'grant_type'    => $this->grantType);

        return $this->generateAccess($query, $code, $refreshToken);
    }
172770
protected function issueRefreshToken(AccessTokenEntityInterface $accessToken, ClientEntityInterface $client = null)
    {
        $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;

        $refreshToken = $this->refreshTokenRepository->getNewRefreshToken();
        $refreshToken->setAccessToken($accessToken);
        $refreshToken->setUUID($accessToken->getUUID());

        $refresh_expire = $client->getRefreshExpire();

        if(!empty($refresh_expire)){
            $refreshToken->setExpiryDateTime(now()->addMinutes($refresh_expire));
        }else{
            $refreshToken->setExpiryDateTime((new DateTime())->add($this->refreshTokenTTL));
        }


        while ($maxGenerationAttempts-- > 0) {
            $refreshToken->setIdentifier($this->generateUniqueIdentifier());
            try {
                $this->refreshTokenRepository->persistNewRefreshToken($refreshToken);

                return $refreshToken;
            } catch (UniqueTokenIdentifierConstraintViolationException $e) {
                if ($maxGenerationAttempts === 0) {
                    throw $e;
                }
            }
        }
    }
278653
public function getRefreshToken($refresh_token)
    {
        $result = $this->client->getItem(array(
            "TableName"=> $this->config['refresh_token_table'],
            "Key" => array('refresh_token'   => array('S' => $refresh_token))
        ));
        if ($result->count()==0) {
            return false ;
        }
        $token = $this->dynamo2array($result);
        $token['expires'] = strtotime($token['expires']);

        return $token;
    }
1293302
public function refresh($refreshToken)
    {
        $queryStr = [
            'appid'         => $this->getAppId(),
            'grant_type'    => 'refresh_token',
            'refresh_token' => $refreshToken,
        ];

        $this->apitype = 'sns';
        $this->module  = 'oauth2';
        $res           = $this->_get('refresh_token', $queryStr);

        return $res;
    }
984289
public function invalidateCurrentRefreshToken()
    {
        if ($this->grant === 'client_credentials') {
            return;
        }

        $token = $this->getAccessToken();
        if ($token) {
            $this->invalidateRefreshToken($token);
        }
    }
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);
    }
1339532
public function invalidateRefreshToken(AccessToken $token)
    {
        $this->getAuthorizationServer()->getAuthenticatedRequest('DELETE',
            $this->authorizationServerUri . '/v2/auth/token', $token, [
                'json' => [
                    'token' => $token->getRefreshToken(),
                ],
            ]);

        $user = $this->getFrameworkBridge()->getUser($token->getResourceOwnerId());
        $user->clearOAuthToken();
    }
1246111
public function getToken($forceRefresh = false)
    {
        $cached = $this->authorization->getAuthorizerAccessToken();

        if ($forceRefresh || empty($cached)) {
            return $this->refreshToken();
        }

        return $cached;
    }
1267698
public function refreshToken(AccessToken $accessToken)
    {
        // request data
        $refreshToken = $accessToken->getRefreshToken();
        $scope        = $accessToken->getScope();

        if (empty($refreshToken)) {
            throw new RuntimeException('No refresh token was set');
        }

        $data = array(
            'grant_type'    => 'refresh_token',
            'refresh_token' => $refreshToken,
        );

        if (!empty($scope)) {
            $data['scope'] = $scope;
        }

        // authentication
        $header = array();

        if ($this->type == self::AUTH_BASIC) {
            $header['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
        }

        if ($this->type == self::AUTH_POST) {
            $data['client_id']     = $this->clientId;
            $data['client_secret'] = $this->clientSecret;
        }

        $request  = new PostRequest($this->url, $header, $data);
        $response = $this->httpClient->request($request);

        $data = Json\Parser::decode($response->getBody());

        if ($response->getStatusCode() == 200) {
            return $this->newToken($data);
        } else {
            throw new RuntimeException('Could not refresh access 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;
    }
168892
public function buildUrlParams($refreshToken)
    {
        $params = 'client_id=' . $this->helper->getWebsiteConfig(
            \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID
        )
            . '&client_secret=' . $this->helper->getWebsiteConfig(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID
            )
            . '&refresh_token=' . $refreshToken . '&grant_type=refresh_token';

        return $params;
    }
617832
public function setRefreshToken($refreshToken)
    {
        if (in_array('refresh_token', $this->persistantMap)) {
            $this->store->set('refresh_token', $refreshToken);
        }

        $this->refreshToken = $refreshToken;
        return $this;
    }
683716
protected function createAccessTokenFromRefreshToken(Token $refreshToken)
    {
        $logger = $this->getLogger();
        $logger->debug('Starting request to create fresh access token from refresh token');

        $body = [
            'client_id' => 'anonymous',
            'grant_type' => 'refresh_token',
            'refresh_token' => $refreshToken->getTokenString(),
        ];

        $response = $this->sendPostRequest($body);

        $logger->debug('Successfully retrieved new access token', $response);

        return new Token(
            $response['access_token'],
            $this->tokenExtractor->extract($response['access_token'])
        );
    }