Skip to content

Commit

Permalink
Merge pull request #61 from bookboon/hotfix/client-options
Browse files Browse the repository at this point in the history
feat: add clientOptions to OauthClient
  • Loading branch information
lkm authored May 10, 2021
2 parents 2fce936 + adfbef3 commit d9e5f2f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
25 changes: 21 additions & 4 deletions src/Client/Oauth/BookboonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ protected function getDefaultHeaders()
$headers = parent::getDefaultHeaders();

foreach ($this->getParentRequestHeaders() as $key => $value) {
if (stripos($key, 'x-b3-') !== false
|| stripos($key, 'x-request-id') !== false
|| stripos($key, 'sentry-trace') !== false
) {
if (stripos($key, 'x-b3-') !== false || stripos($key, 'x-request-id') !== false) {
$headers[$key] = $value;
}
}
Expand All @@ -200,4 +197,24 @@ protected function getParentRequestHeaders(): array

return apache_request_headers();
}

/**
* Returns the list of options that can be passed to the HttpClient
*
* @param array $options An array of options to set on this provider.
* Options include `clientId`, `clientSecret`, `redirectUri`, and `state`.
* Individual providers may introduce more options, as needed.
* @return array The options to pass to the HttpClient constructor
*/
protected function getAllowedClientOptions(array $options)
{
$client_options = ['timeout', 'proxy', 'handler'];

// Only allow turning off ssl verification if it's for a proxy
if (!empty($options['proxy'])) {
$client_options[] = 'verify';
}

return $client_options;
}
}
31 changes: 18 additions & 13 deletions src/Client/OauthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ class OauthClient implements ClientInterface
* @param string $apiSecret
* @param Headers $headers
* @param array $scopes
* @param CacheInterface $cache
* @param string $redirectUri
* @param string $appUserId
* @param CacheInterface|null $cache
* @param string|null $redirectUri
* @param string|null $appUserId
* @param string|null $authServiceUri
* @param string|null $apiUri
* @param LoggerInterface|null $logger
* @param array $clientOptions
* @throws UsageException
*/
public function __construct(
Expand All @@ -67,19 +68,23 @@ public function __construct(
?string $appUserId = null,
?string $authServiceUri = null,
?string $apiUri = null,
LoggerInterface $logger = null
LoggerInterface $logger = null,
array $clientOptions = []
) {
if (empty($apiId)) {
throw new UsageException("Client id is required");
}

$options = [
'clientId' => $apiId,
'clientSecret' => $apiSecret,
'scope' => $scopes,
'redirectUri' => $redirectUri,
'baseUri' => $authServiceUri,
];
$clientOptions = array_merge(
$clientOptions,
[
'clientId' => $apiId,
'clientSecret' => $apiSecret,
'scope' => $scopes,
'redirectUri' => $redirectUri,
'baseUri' => $authServiceUri,
]
);

if ($logger !== null) {
$this->requestOptions = [
Expand All @@ -98,8 +103,8 @@ public function __construct(
];
}

$options['requestOptions'] = $this->requestOptions;
$this->provider = new BookboonProvider($options);
$clientOptions['requestOptions'] = $this->requestOptions;
$this->provider = new BookboonProvider($clientOptions);

$this->setApiId($apiId);
$this->setCache($cache);
Expand Down

0 comments on commit d9e5f2f

Please sign in to comment.