Refreshes the access token

@throws  \Exception
503047
private function refreshAccessToken() {
        // Setup the params
        $params = [
            'client_id'     => $this->clientID,
            'client_secret' => $this->secret,
            'grant_type'    => 'refresh_token',
            'refresh_token' => $this->refreshToken
        ];

        // Parse the cURL result
        $this->parseAccessToken(CURL::post($this->url, $params));
    }
1143792
public function acquireAccessToken() {
    $grant = new PasswordGrant($this->clientId, $this->clientSecret, $this->username, $this->password, $this->scopes);
    $tokens = $grant->getTokens();

    $accessToken = $tokens->{"access_token"};
    $refreshToken = $tokens->{"refresh_token"};
    $expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"});

    return new RefreshableAccessToken($this->clientId, $this->clientSecret, $accessToken, $expiresAt, $refreshToken);
  }
241278
private function getAccessToken(): void
    {
        if ($this->tokenStorage->getRefreshToken()) {
            $body = [
                'grant_type' => 'refresh_token',
                'refresh_token' => $this->tokenStorage->getRefreshToken(),
            ];
        } else {
            $body = [
                'grant_type' => 'password',
                'username' => $this->username,
                'password' => $this->password,
            ];
            if (!empty($this->mfaToken)) {
                $body['mfa_token'] = $this->mfaToken;
            }
            if (!empty($this->scope)) {
                $body['scope'] = $this->scope;
            }
        }

        try {
            $response = $this->authClient()->post('', http_build_query($body), ['Content-Type' => 'application/x-www-form-urlencoded']);
            $this->tokenStorage->saveToken(json_decode((string) $response->getBody(), true));
        } catch (OauthRefreshTokenExpiredException $e) {
            // Clear data in token storage because refresh token has expired.
            $this->tokenStorage->removeToken();
            // Try to automatically get a new access token by sending client
            // id and secret.
            $this->getAccessToken();
        } catch (Exception $e) {
            throw new OauthAuthenticationException($e->getMessage(), $e->getCode(), $e);
        }
    }
544600
private function refresh(): void
    {
        $time = \time();

        if (isset($this->data['time']) && $this->data['time'] <= ($time - $this->expire)) {

            //delete session data
            $this->data = [];

            //regenerate session
            $this->regenerate();
        }

        $this->setSessionData($time);
    }
1031648
public function clearOAuthToken()
    {
        $this->access_token = null;
        $this->access_token_expiration = null;
        $this->refresh_token = null;
    }
871297
public function refreshToken()
    {
        if (!$this->_restclient) {
            $this->_restclient = new RestClient();
        }
        $data = ['grant_type'    => 'refresh_token',
                'refresh_token'     => $this->get('REFRESH_TOKEN'),
                'client_secret' => $this->get('ACCESS_TOKEN')];
        $this->_restclient->setHttpParam('address', $this->get('base_url'));
        $response = $this->_restclient->post("/oauth/token", ['json_data' => json_encode($data)]);
        if (isset($response['access_token']) && isset($response['refresh_token']) && isset($response['client_id']) && isset($response['client_secret'])) {
            parent::set('ACCESS_TOKEN', $response['access_token']);
            parent::set('REFRESH_TOKEN', $response['refresh_token']);
        }
        return $response['body'];
    }
989184
def refresh(self, access_token=None, **kwargs):
        
        if not self.token_lock.locked():
            with self.token_lock:
                if access_token == self.access_token or access_token is None:
                    if self.developer_token is not None:
                        r = self._httpclient.request(
                            method='POST',
                            url=self.developer_token_url,
                            path='/request_token',
                            headers={
                                'Authorization': 'Bearer {}'.format(
                                    self.developer_token
                                )
                            },
                            timeout=30,
                            raise_for_status=True
                        )

                    elif all(
                        [
                            self.client_id,
                            self.client_secret,
                            self.refresh_token
                        ]
                    ):
                        data = {
                            'client_id': self.client_id,
                            'client_secret': self.client_secret,
                            'refresh_token': self.refresh_token,
                            'grant_type': 'refresh_token'
                        }
                        r = self._httpclient.request(
                            method='POST',
                            url=self.token_url,
                            json=data,
                            path='/api/oauth2/RequestToken',
                            **kwargs
                        )
                    else:
                        raise PartialCredentialsError(
                            "Missing one or more required credentials"
                        )

                    if r:
                        if not r.ok:
                            raise PanCloudError(
                                '%s %s: %s' % (
                                r.status_code, r.reason, r.text)
                            )
                        try:
                            r_json = r.json()
                        except ValueError as e:
                            raise PanCloudError("Invalid JSON: %s" % e)
                        else:
                            if r.json().get(
                                'error_description'
                            ) or r.json().get(
                                'error'
                            ):
                                raise PanCloudError(r.text)
                            self.access_token = r_json.get(
                                'access_token', None
                            )
                            self.jwt_exp = self._decode_exp(
                                self.access_token_)
                            if r_json.get('refresh_token', None):
                                self.refresh_token = \
                                    r_json.get('refresh_token')
                            self.write_credentials()
                        return self.access_token_
984289
public function invalidateCurrentRefreshToken()
    {
        if ($this->grant === 'client_credentials') {
            return;
        }

        $token = $this->getAccessToken();
        if ($token) {
            $this->invalidateRefreshToken($token);
        }
    }
90798
def _refresh(self, _):
        
        # pylint: disable=import-error
        from google.appengine.api import app_identity
        try:
            token, _ = app_identity.get_access_token(self._scopes)
        except app_identity.Error as e:
            raise exceptions.CredentialsError(str(e))
        self.access_token = token
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;
    }
1081575
def refresh_token(self):
        """"""
        if (not self.auth_details or
                not 'refresh_token' in self.auth_details or
                not self.auth_details['refresh_token']):
            raise Exception(
                "auth_details['refresh_token'] does not contain a refresh token.")

        refresh_token = self.auth_details['refresh_token']
        params = [
            ('grant_type', 'refresh_token'),
            ('refresh_token', refresh_token)
        ]
        response = self._post('', urlencode(params),
                              CreateSend.oauth_token_uri, "application/x-www-form-urlencoded")
        new_access_token, new_expires_in, new_refresh_token = None, None, None
        r = json_to_py(response)
        new_access_token, new_expires_in, new_refresh_token = r.access_token, r.expires_in, r.refresh_token
        self.auth({
            'access_token': new_access_token,
            'refresh_token': new_refresh_token})
        return [new_access_token, new_expires_in, new_refresh_token]
78046
public function refreshToken($accessToken = null)
    {
        $accessToken = $accessToken ?: $this->accessToken;
        $this->accessToken = $this->provider->getAccessToken('refresh_token', [
            'refresh_token' => $accessToken->getRefreshToken()
        ]);
        return $this->accessToken;
    }
675566
def refresh_access_token(self, refresh_token):
        ''' 
        '''
        request = self._get_request()
        response = request.post(self.OAUTH_TOKEN_URL, {
            "grant_type": "refresh_token",
            "refresh_token": refresh_token
        })
        self.auth = HSAccessTokenAuth.from_response(response)
        return self.auth.access_token
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;
    }
571663
protected function refreshAccessToken($token)
    {
        switch ($this->grant) {
            case 'provided_token':
                throw new UnauthorizedException('[internal]', 'The provided token expired.');

            case 'client_credentials':
                return $this->getTokenByClientCredentialsGrant();

            case 'authorization_code':
                return $this->getTokenByRefreshTokenGrant($token);

            default:
                throw new \Exception('Unsupported grant type. Check $this->grant.');
        }
    }
25462
public function refresh()
    {
        if ($this->ID && $this->HailID) {
            try {
                $api_client = new Client();
                $data = $api_client->getOne($this);
            } catch (\Exception $ex) {
                return $this;
            }
            if (count($data) > 0) {
                $this->importHailData($data);
            }
        }

        return $this;
    }
1009776
public function refreshToken() {
        if (!$this->delete()) {
            return false;
        }
        $this->isNewRecord = true;
        $this->refresh_token = $this->generateAccessToken();
        $this->expires = Time::timestamp(time() + 3600 * 24 * 365);
        $this->save();
        return OAuthAccessTokenModel::createToken($this->client_id, $this->user_id);
    }