diff --git a/src/API/Management/Clients.php b/src/API/Management/Clients.php index e94ec306..52bacb0a 100644 --- a/src/API/Management/Clients.php +++ b/src/API/Management/Clients.php @@ -9,6 +9,9 @@ use Auth0\SDK\Utility\Toolkit; use Psr\Http\Message\ResponseInterface; +use function array_key_exists; +use function is_array; + /** * Handles requests to the Clients endpoint of the v2 Management API. * @@ -180,6 +183,10 @@ public function update( [$id, \Auth0\SDK\Exception\ArgumentException::missing('id')], ])->isString(); + if (is_array($body) && array_key_exists('initiate_login_uri', $body) && null === $body['initiate_login_uri']) { + $body['initiate_login_uri'] = ''; + } + return $this->getHttpClient() ->method('patch')->addPath(['clients', $id]) ->withBody($body ?? []) diff --git a/tests/Unit/API/Management/ClientsTest.php b/tests/Unit/API/Management/ClientsTest.php index 2f518e9d..bc5fd17b 100644 --- a/tests/Unit/API/Management/ClientsTest.php +++ b/tests/Unit/API/Management/ClientsTest.php @@ -68,6 +68,18 @@ expect($body['name'])->toEqual('__test_new_name__'); }); +test('update() does NOT nullify empty `initiate_login_uri` values', function(): void { + $this->endpoint->update('__test_id__', ['name' => '__test_new_name__', 'initiate_login_uri' => '']); + + expect($this->api->getRequestMethod())->toEqual('PATCH'); + expect($this->api->getRequestUrl())->toEndWith('/api/v2/clients/__test_id__'); + + $body = $this->api->getRequestBody(); + $this->assertArrayHasKey('name', $body); + expect($body['name'])->toEqual('__test_new_name__'); + expect($body['initiate_login_uri'])->toEqual(''); +}); + test('getCredentials() issues an appropriate request', function(): void { $mockClientId = uniqid(); $this->endpoint->getCredentials($mockClientId, ['client_id' => '__test_client_id__', 'app_type' => '__test_app_type__']);