Skip to content

Commit

Permalink
Adds in logic to renew the token if it has expired.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Feb 17, 2020
1 parent 908bfe3 commit e643cec
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Connector/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use League\OAuth2\Client\Provider\GenericProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessTokenInterface;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\BadResponseException;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -32,7 +33,7 @@ class Connector implements ConnectorInterface
protected $provider;

/**
* @var string The generated OAuth 2.0 access token.
* @var AccessTokenInterface|string The generated OAuth 2.0 access token.
*/
protected $accessToken;

Expand Down Expand Up @@ -62,7 +63,7 @@ public function __construct(array $config)
*/
public function createRequest($verb, $path)
{
if (!isset($this->accessToken)) {
if (!isset($this->accessToken) || $this->accessToken->hasExpired()) {
$this->accessToken = $this->provider->getAccessToken('client_credentials');
}

Expand Down

0 comments on commit e643cec

Please sign in to comment.