From 5a2ac50e5281ae3791ee464c065ae55a5f5cba6f Mon Sep 17 00:00:00 2001 From: James Seconde Date: Mon, 13 Feb 2023 11:06:08 +0000 Subject: [PATCH] added missing query string auth, add to account api (#372) --- src/Account/ClientFactory.php | 3 ++- .../Credentials/Handler/BasicQueryHandler.php | 17 ++++++++++++++ test/Account/ClientTest.php | 5 ++++ .../Handler/BasicQueryHandlerTest.php | 23 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Client/Credentials/Handler/BasicQueryHandler.php create mode 100644 test/Client/Credentials/Handler/BasicQueryHandlerTest.php diff --git a/src/Account/ClientFactory.php b/src/Account/ClientFactory.php index 2d5540e7..850dea8b 100644 --- a/src/Account/ClientFactory.php +++ b/src/Account/ClientFactory.php @@ -14,6 +14,7 @@ use Psr\Container\ContainerInterface; use Vonage\Client\APIResource; use Vonage\Client\Credentials\Handler\BasicHandler; +use Vonage\Client\Credentials\Handler\BasicQueryHandler; class ClientFactory { @@ -25,7 +26,7 @@ public function __invoke(ContainerInterface $container): Client ->setBaseUrl($accountApi->getClient()->getRestUrl()) ->setIsHAL(false) ->setBaseUri('/account') - ->setAuthHandler(new BasicHandler()) + ->setAuthHandler(new BasicQueryHandler()) ; return new Client($accountApi); diff --git a/src/Client/Credentials/Handler/BasicQueryHandler.php b/src/Client/Credentials/Handler/BasicQueryHandler.php new file mode 100644 index 00000000..857ccffd --- /dev/null +++ b/src/Client/Credentials/Handler/BasicQueryHandler.php @@ -0,0 +1,17 @@ +extract(Basic::class, $credentials); + + return $request->withUri($request->getUri()->withQuery(http_build_query($credentials->asArray()))); + } +} \ No newline at end of file diff --git a/test/Account/ClientTest.php b/test/Account/ClientTest.php index d32c7ac8..0dbe1582 100644 --- a/test/Account/ClientTest.php +++ b/test/Account/ClientTest.php @@ -56,6 +56,7 @@ public function setUp(): void $this->api = new APIResource(); $this->api->setBaseUrl('https://rest.nexmo.com') ->setIsHAL(false) + ->setAuthHandler(new Client\Credentials\Handler\BasicQueryHandler()) ->setBaseUri('/account'); $this->api->setClient($this->vonageClient->reveal()); @@ -163,6 +164,10 @@ public function testGetBalance(): void $this->assertEquals('rest.nexmo.com', $request->getUri()->getHost()); $this->assertEquals('GET', $request->getMethod()); + $uri = $request->getUri(); + $uriString = $uri->__toString(); + $this->assertEquals('https://rest.nexmo.com/account/get-balance?api_key=abc&api_secret=def', $uriString); + return true; }))->shouldBeCalledTimes(1)->willReturn($this->getResponse('get-balance')); diff --git a/test/Client/Credentials/Handler/BasicQueryHandlerTest.php b/test/Client/Credentials/Handler/BasicQueryHandlerTest.php new file mode 100644 index 00000000..82759f51 --- /dev/null +++ b/test/Client/Credentials/Handler/BasicQueryHandlerTest.php @@ -0,0 +1,23 @@ +getUri(); + $uriString = $uri->__toString(); + $this->assertEquals('https://example.com?api_key=abc&api_secret=xyz', $uriString); + } +} \ No newline at end of file