Skip to content

Commit

Permalink
Merge pull request #64 from bshaffer/pushes-http-client-to-authtoken-…
Browse files Browse the repository at this point in the history
…fetcher

ensures AuthTokenFetcher receives the Guzzle Client passed to getFetcher
  • Loading branch information
tbetbetbe committed Sep 16, 2015
2 parents c9511cf + 42830b1 commit 6be3d15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ApplicationDefaultCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function getFetcher(
CacheInterface $cache = null)
{
$creds = self::getCredentials($scope, $client);
return new AuthTokenFetcher($creds, $cacheConfig, $cache);
return new AuthTokenFetcher($creds, $cacheConfig, $cache, $client);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/AuthTokenFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use GuzzleHttp\Event\RequestEvents;
use GuzzleHttp\Event\SubscriberInterface;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\ClientInterface;

/**
* AuthTokenFetcher is a Guzzle Subscriber that adds an Authorization header
Expand All @@ -40,6 +41,9 @@ class AuthTokenFetcher implements SubscriberInterface
/** @var An implementation of CacheInterface */
private $cache;

/** @var An implementation of ClientInterface */
private $client;

/** @var An implementation of FetchAuthTokenInterface */
private $fetcher;

Expand All @@ -55,9 +59,11 @@ class AuthTokenFetcher implements SubscriberInterface
*/
public function __construct(FetchAuthTokenInterface $fetcher,
array $cacheConfig = null,
CacheInterface $cache = null)
CacheInterface $cache = null,
ClientInterface $client = null)
{
$this->fetcher = $fetcher;
$this->client = $client;
if (!is_null($cache)) {
$this->cache = $cache;
$this->cacheConfig = Collection::fromConfig($cacheConfig, [
Expand Down Expand Up @@ -113,7 +119,7 @@ public function onBefore(BeforeEvent $event)
}

// Fetch the auth token.
$auth_tokens = $this->fetcher->fetchAuthToken();
$auth_tokens = $this->fetcher->fetchAuthToken($this->client);
if (array_key_exists('access_token', $auth_tokens)) {
$request->setHeader('Authorization', 'Bearer ' . $auth_tokens['access_token']);
$this->setCachedValue($auth_tokens['access_token']);
Expand Down

0 comments on commit 6be3d15

Please sign in to comment.