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);
        }
    }
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);
        }
    }
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 ) ; } }
Retrieves access token and saves it to the token storage.

@psalm-suppress InvalidCatch - Exception by interface can be caught in PHP >= 7.1.
Retrieves access token and saves it to the token storage .