Skip to content

Commit

Permalink
prototype for passing the Client ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Dec 7, 2024
1 parent 876f14a commit 2c83660
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Credentials/UserRefreshCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ public function __construct(
* @type string $id_token
* }
*/
public function fetchAuthToken(?callable $httpHandler = null, array $headers = [])
public function fetchAuthToken(?callable $httpHandler = null, array $headers = [], ?string $clientId = null)
{
return $this->auth->fetchAuthToken(
$httpHandler,
$this->applyTokenEndpointMetrics($headers, $this->isIdTokenRequest ? 'it' : 'at')
$this->applyTokenEndpointMetrics($headers, $this->isIdTokenRequest ? 'it' : 'at'),
$clientId
);
}

Expand Down
10 changes: 6 additions & 4 deletions src/FetchAuthTokenCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public function getFetcher()
* @return array<mixed> the response
* @throws \Exception
*/
public function fetchAuthToken(?callable $httpHandler = null)
public function fetchAuthToken(?callable $httpHandler = null, ?string $clientId = null)
{
if ($cached = $this->fetchAuthTokenFromCache()) {
return $cached;
}

$auth_token = $this->fetcher->fetchAuthToken($httpHandler);
$auth_token = $this->fetcher->fetchAuthToken($httpHandler, [], $clientId);

Check failure on line 89 in src/FetchAuthTokenCache.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis

Method Google\Auth\FetchAuthTokenInterface::fetchAuthToken() invoked with 3 parameters, 0-1 required.

$this->saveAuthTokenInCache($auth_token);

Expand Down Expand Up @@ -235,7 +235,8 @@ public function getUniverseDomain(): string
public function updateMetadata(
$metadata,
$authUri = null,
?callable $httpHandler = null
?callable $httpHandler = null,
?string $clientId = null,
) {
if (!$this->fetcher instanceof UpdateMetadataInterface) {
throw new \RuntimeException(
Expand Down Expand Up @@ -263,7 +264,8 @@ public function updateMetadata(
$newMetadata = $this->fetcher->updateMetadata(

Check failure on line 264 in src/FetchAuthTokenCache.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis

Method Google\Auth\UpdateMetadataInterface::updateMetadata() invoked with 4 parameters, 1-3 required.
$metadata,
$authUri,
$httpHandler
$httpHandler,
$clientId
);

if (!$cached && $token = $this->fetcher->getLastReceivedToken()) {
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,13 @@ public function generateCredentialsRequest(?callable $httpHandler = null, array
* endpoint request.
* @return array<mixed> the response
*/
public function fetchAuthToken(?callable $httpHandler = null, array $headers = [])
public function fetchAuthToken(?callable $httpHandler = null, array $headers = [], string $clientId = null)
{
if (is_null($httpHandler)) {
$httpHandler = HttpHandlerFactory::build(HttpClientCache::getHttpClient());
}

$response = $httpHandler($this->generateCredentialsRequest($httpHandler, $headers));
$response = $httpHandler($this->generateCredentialsRequest($httpHandler, $headers), ['clientId' => $clientId ]);
$credentials = $this->parseTokenResponse($response);
$this->updateToken($credentials);
if (isset($credentials['scope'])) {
Expand Down
5 changes: 3 additions & 2 deletions src/UpdateMetadataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function getUpdateMetadataFunc()
public function updateMetadata(
$metadata,
$authUri = null,
?callable $httpHandler = null
?callable $httpHandler = null,
?string $clientId = null,
) {
$metadata_copy = $metadata;

Expand All @@ -63,7 +64,7 @@ public function updateMetadata(
// Auth metadata has already been set
return $metadata_copy;
}
$result = $this->fetchAuthToken($httpHandler);
$result = $this->fetchAuthToken($httpHandler, [], $clientId);
if (isset($result['access_token'])) {
$metadata_copy[self::AUTH_METADATA_KEY] = ['Bearer ' . $result['access_token']];
} elseif (isset($result['id_token'])) {
Expand Down

0 comments on commit 2c83660

Please sign in to comment.