Skip to content

Commit

Permalink
Separate Guzzle Client for oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
dpslwk committed Jan 11, 2021
1 parent 90e9f33 commit b1442e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All Notable changes to `ViMbAdminClient` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 1.1.3 (released 2021-01-11)

### Fixed
- Remove defaults from config
- Separate Guzzle Client for oauth

## 1.1.2 (released 2020-03-06)

### Fixed
Expand Down
23 changes: 16 additions & 7 deletions src/ViMbAdminClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ public function setupClient(
string $clientSecret,
$tokenUri = '/oauth/token')
{
$handlerStack = HandlerStack::create();
$client = new Client(
$oauthClient = new Client(
[
'handler'=> $handlerStack,
'base_uri' => $apiUrl,
'auth' => 'oauth2',
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
Expand All @@ -128,8 +125,8 @@ public function setupClient(
ClientCredentials::CONFIG_TOKEN_URL => $tokenUri,
];

$grant = new ClientCredentials($client, $config);
$middleware = new ViMbAdminOAuthMiddleware($client, $grant, null, $this->tokenStore);
$grant = new ClientCredentials($oauthClient, $config);
$middleware = new ViMbAdminOAuthMiddleware($oauthClient, $grant, null, $this->tokenStore);

// see if we have a token already and load it.
$key = $this->tokenStore->serializeKey($grant);
Expand All @@ -143,10 +140,22 @@ public function setupClient(
$middleware->setAccessToken($accessToken);
}

$handlerStack = HandlerStack::create();
$handlerStack->push($middleware->onBefore());
$handlerStack->push($middleware->onFailure(5));

$this->client = $client;
$this->client = new Client(
[
'handler'=> $handlerStack,
'base_uri' => $apiUrl,
'auth' => 'oauth2',
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'exceptions' => false,
]
);
$this->isInitialised = true;

return $this;
Expand Down

0 comments on commit b1442e9

Please sign in to comment.