src/AuthorizesWithOAuth2.php
protected function getAuthorizationHeader($forceRefresh = false)
    {
        $token = $this->getAccessToken();

        // If we're using a token provided with the request, return it.
        if ($this->grant === 'provided_token') {
            return ['Authorization' => 'Bearer ' . $token->getToken()];
        }

        // Don't attempt to refresh token if there isn't a logged-in user.
        $user = $this->getFrameworkBridge()->getCurrentUser();
        if ($this->grant === 'authorization_code' && ! $user) {
            return [];
        }

        // If the token is expired, fetch a new one before making the request.
        if (! $token || ($token && $token->hasExpired()) || $forceRefresh) {
            $token = $this->refreshAccessToken($token);
        }

        return $this->getAuthorizationServer()->getHeaders($token);
    }
protected function getAuthorizationHeader($forceRefresh = false)
    {
        $token = $this->getAccessToken();

        // If we're using a token provided with the request, return it.
        if ($this->grant === 'provided_token') {
            return ['Authorization' => 'Bearer ' . $token->getToken()];
        }

        // Don't attempt to refresh token if there isn't a logged-in user.
        $user = $this->getFrameworkBridge()->getCurrentUser();
        if ($this->grant === 'authorization_code' && ! $user) {
            return [];
        }

        // If the token is expired, fetch a new one before making the request.
        if (! $token || ($token && $token->hasExpired()) || $forceRefresh) {
            $token = $this->refreshAccessToken($token);
        }

        return $this->getAuthorizationServer()->getHeaders($token);
    }
protected function getAuthorizationHeader ( $ forceRefresh = false ) { $ token = $ this -> getAccessToken ( ) ; // If we're using a token provided with the request, return it. if ( $ this -> grant === 'provided_token' ) { return [ 'Authorization' => 'Bearer ' . $ token -> getToken ( ) ] ; } // Don't attempt to refresh token if there isn't a logged-in user. $ user = $ this -> getFrameworkBridge ( ) -> getCurrentUser ( ) ; if ( $ this -> grant === 'authorization_code' && ! $ user ) { return [ ] ; } // If the token is expired, fetch a new one before making the request. if ( ! $ token || ( $ token && $ token -> hasExpired ( ) ) || $ forceRefresh ) { $ token = $ this -> refreshAccessToken ( $ token ) ; } return $ this -> getAuthorizationServer ( ) -> getHeaders ( $ token ) ; }
Get the authorization header for a request, if needed.
Overrides this empty method in RestApiClient.

@param bool $forceRefresh - Should the token be refreshed, even if expiration timestamp hasn't passed?
@return array
@throws \Exception
Get the authorization header for a request if needed . Overrides this empty method in RestApiClient .