From 52691de56fb0ff3cd09a457796db78aba461af91 Mon Sep 17 00:00:00 2001 From: chadicus Date: Mon, 11 Nov 2024 15:15:39 -0500 Subject: [PATCH] Fix full URL issue in createApiGatewayClientCredentials --- src/Authentication.php | 15 ++++++--------- tests/AuthenticationTest.php | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Authentication.php b/src/Authentication.php index df871ff..49d303b 100644 --- a/src/Authentication.php +++ b/src/Authentication.php @@ -141,18 +141,16 @@ public static function createOwnerCredentials( /** * Creates a new instance of Authentication for Client Credentials grant type * - * @param string $clientId The oauth client id - * @param string $clientSecret The oauth client secret - * @param string $authUrl The oauth auth url - * @param string $tokenResource The access token resource of the API + * @param string $clientId The oauth client id + * @param string $clientSecret The oauth client secret + * @param string $authUrl The oauth auth url * * @return Authentication */ public static function createApiGatewayClientCredentials( string $clientId, string $clientSecret, - string $authUrl, - string $tokenResource = 'token' + string $authUrl ) : Authentication { $getTokenRequestFunc = function ( string $unusedBaseUrl, @@ -160,13 +158,12 @@ public static function createApiGatewayClientCredentials( ) use ( $clientId, $clientSecret, - $authUrl, - $tokenResource + $authUrl ) { $data = ['client_id' => $clientId, 'client_secret' => $clientSecret, 'grant_type' => 'client_credentials']; return new Request( 'POST', - "{$authUrl}/oauth2/{$tokenResource}", + $authUrl, ['Content-Type' => 'application/x-www-form-urlencoded'], Http::buildQueryString($data) ); diff --git a/tests/AuthenticationTest.php b/tests/AuthenticationTest.php index be33c5e..a1a6e2d 100644 --- a/tests/AuthenticationTest.php +++ b/tests/AuthenticationTest.php @@ -186,7 +186,7 @@ public function getTokenRequestApiGatewayClientCredentials() { $auth = Authentication::createApiGatewayClientCredentials('id', 'secret', 'authUrl'); $request = $auth->getTokenRequest('baseUrl'); - $this->assertSame('authUrl/oauth2/token', (string)$request->getUri()); + $this->assertSame('authUrl', (string)$request->getUri()); $this->assertSame('POST', $request->getMethod()); $this->assertSame( 'client_id=id&client_secret=secret&grant_type=client_credentials',