diff --git a/src/Http/HttpMethodsTrait.php b/src/Http/HttpMethodsTrait.php index 6e9fd7f..f8656f6 100644 --- a/src/Http/HttpMethodsTrait.php +++ b/src/Http/HttpMethodsTrait.php @@ -4,6 +4,7 @@ use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Http\Client\HttpClient; +use Psr\Http\Message\ResponseInterface; use Bokbasen\Auth\Login; /** @@ -88,4 +89,21 @@ protected function makeHeadersArray(Login $auth, array $customHeaders = []) { return array_merge($auth->getAuthHeadersAsArray(), $customHeaders); } + + /** + * Check if the auth client should attempt reauthetication based on response. + * Will only run reauth once. + * + * @param ResponseInterface $response + * @return boolean + */ + protected function needReAuthentication(ResponseInterface $response) + { + if ($response->getStatusCode() == 401 && ! $this->auth->isReAuthAttempted()) { + $this->auth->reAuthenticate(); + return true; + } else { + return false; + } + } } \ No newline at end of file