From 2c8366008d8376643d843b56e546eed0a9a0f58e Mon Sep 17 00:00:00 2001 From: Hector Mendoza Jacobo Date: Sat, 7 Dec 2024 00:10:29 +0000 Subject: [PATCH] prototype for passing the Client ID --- src/Credentials/UserRefreshCredentials.php | 5 +++-- src/FetchAuthTokenCache.php | 10 ++++++---- src/OAuth2.php | 4 ++-- src/UpdateMetadataTrait.php | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Credentials/UserRefreshCredentials.php b/src/Credentials/UserRefreshCredentials.php index 1127ec6be..4d78df49d 100644 --- a/src/Credentials/UserRefreshCredentials.php +++ b/src/Credentials/UserRefreshCredentials.php @@ -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 ); } diff --git a/src/FetchAuthTokenCache.php b/src/FetchAuthTokenCache.php index 73901c3d8..a8a7856b7 100644 --- a/src/FetchAuthTokenCache.php +++ b/src/FetchAuthTokenCache.php @@ -80,13 +80,13 @@ public function getFetcher() * @return array 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); $this->saveAuthTokenInCache($auth_token); @@ -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( @@ -263,7 +264,8 @@ public function updateMetadata( $newMetadata = $this->fetcher->updateMetadata( $metadata, $authUri, - $httpHandler + $httpHandler, + $clientId ); if (!$cached && $token = $this->fetcher->getLastReceivedToken()) { diff --git a/src/OAuth2.php b/src/OAuth2.php index c60b8827f..aac23c1e8 100644 --- a/src/OAuth2.php +++ b/src/OAuth2.php @@ -669,13 +669,13 @@ public function generateCredentialsRequest(?callable $httpHandler = null, array * endpoint request. * @return array 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'])) { diff --git a/src/UpdateMetadataTrait.php b/src/UpdateMetadataTrait.php index 486ec72a5..a15f4b8de 100644 --- a/src/UpdateMetadataTrait.php +++ b/src/UpdateMetadataTrait.php @@ -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; @@ -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'])) {