Skip to content

Commit

Permalink
Added method to check response and determine if a reauthetication sho…
Browse files Browse the repository at this point in the history
…uld be attempted
  • Loading branch information
Ketil Stadskleiv committed Oct 14, 2016
1 parent 9002f60 commit 852ddad
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Http/HttpMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 852ddad

Please sign in to comment.