Skip to content

Commit

Permalink
[SDK-4665] Support initiate_login_uri property being an empty strin…
Browse files Browse the repository at this point in the history
…g for PATCH /api/v2/clients/:id requests. (#732)

### Changes

This PR adds support for `initiate_login_uri` to be supplied as an empty
string to the `/api/v2/clients/:id` endpoint for `PATCH` requests.

### References

Resolves #731 

### Testing

This PR adds a regression testing for the change.

### Contributor Checklist

- [x] I agree to adhere to the [Auth0 General Contribution
Guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md).
- [x] I agree to uphold the [Auth0 Code of
Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
  • Loading branch information
evansims authored Oct 16, 2023
1 parent 9e0c5ed commit 3474acd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/API/Management/Clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 ?? [])
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/API/Management/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__']);
Expand Down

0 comments on commit 3474acd

Please sign in to comment.