Skip to content

Commit 040153e

Browse files
Adding Support For CYOK (#779)
### Changes - Added postEncryptionRekey() method in KeysManager related to the /keys/encryption/rekey endpoint. ### References - [Public docs](https://auth0.com/docs/secure/highly-regulated-identity/customer-managed-keys#control-your-own-key) - [API docs](https://auth0.com/docs/api/management/v2/keys/post-encryption-rekey#scopes) ### Testing - [x] This change adds test coverage - [x] This change has been tested on the latest version of the platform/language or why not ### 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).
1 parent a16a81d commit 040153e

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

Diff for: src/API/Management.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Auth0\SDK\API;
66

7-
use Auth0\SDK\API\Management\{Actions, AttackProtection, Blacklists, ClientGrants, Clients, Connections, DeviceCredentials, EmailTemplates, Emails, Grants, Guardian, Jobs, LogStreams, Logs, Organizations, ResourceServers, Roles, Rules, Stats, Tenants, Tickets, UserBlocks, Users, UsersByEmail};
7+
use Auth0\SDK\API\Management\{Actions, AttackProtection, Blacklists, ClientGrants, Clients, Connections, DeviceCredentials, EmailTemplates, Emails, Grants, Guardian, Jobs, Keys, LogStreams, Logs, Organizations, ResourceServers, Roles, Rules, Stats, Tenants, Tickets, UserBlocks, Users, UsersByEmail};
88
use Auth0\SDK\Configuration\SdkConfiguration;
9-
use Auth0\SDK\Contract\API\Management\{ActionsInterface, AttackProtectionInterface, BlacklistsInterface, ClientGrantsInterface, ClientsInterface, ConnectionsInterface, DeviceCredentialsInterface, EmailTemplatesInterface, EmailsInterface, GrantsInterface, GuardianInterface, JobsInterface, LogStreamsInterface, LogsInterface, OrganizationsInterface, ResourceServersInterface, RolesInterface, RulesInterface, StatsInterface, TenantsInterface, TicketsInterface, UserBlocksInterface, UsersByEmailInterface, UsersInterface};
9+
use Auth0\SDK\Contract\API\Management\{ActionsInterface, AttackProtectionInterface, BlacklistsInterface, ClientGrantsInterface, ClientsInterface, ConnectionsInterface, DeviceCredentialsInterface, EmailTemplatesInterface, EmailsInterface, GrantsInterface, GuardianInterface, JobsInterface, KeysInterface, LogStreamsInterface, LogsInterface, OrganizationsInterface, ResourceServersInterface, RolesInterface, RulesInterface, StatsInterface, TenantsInterface, TicketsInterface, UserBlocksInterface, UsersByEmailInterface, UsersInterface};
1010
use Auth0\SDK\Contract\API\{AuthenticationInterface, ManagementInterface};
1111
use Auth0\SDK\Utility\{HttpClient, HttpResponse, HttpResponsePaginator};
1212
use Psr\Cache\CacheItemPoolInterface;
@@ -182,6 +182,11 @@ public function jobs(): JobsInterface
182182
return Jobs::instance($this->getHttpClient());
183183
}
184184

185+
public function keys(): KeysInterface
186+
{
187+
return Keys::instance($this->getHttpClient());
188+
}
189+
185190
public function logs(): LogsInterface
186191
{
187192
return Logs::instance($this->getHttpClient());

Diff for: src/API/Management/Keys.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Auth0\SDK\API\Management;
6+
7+
use Auth0\SDK\Contract\API\Management\KeysInterface;
8+
use Auth0\SDK\Utility\Request\RequestOptions;
9+
use Psr\Http\Message\ResponseInterface;
10+
11+
/**
12+
* Handles requests to the Keys endpoint of the v2 Management API.
13+
*
14+
* @see https://auth0.com/docs/api/management/v2/keys
15+
*/
16+
final class Keys extends ManagementEndpoint implements KeysInterface
17+
{
18+
public function postEncryptionRekey(
19+
?RequestOptions $options = null,
20+
): ResponseInterface {
21+
return $this->getHttpClient()
22+
->method('post')
23+
->addPath(['keys', 'encryption', 'rekey'])
24+
->withOptions($options)
25+
->call();
26+
}
27+
}

Diff for: src/Contract/API/Management/KeysInterface.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Auth0\SDK\Contract\API\Management;
6+
7+
use Auth0\SDK\Utility\Request\RequestOptions;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
interface KeysInterface
11+
{
12+
/**
13+
* Perform rekeying operation on the key hierarchy.
14+
* Required scope: `create:encryption_keys`, `update:encryption_keys`.
15+
*
16+
* @param null|RequestOptions $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @see for supported options.)
17+
*
18+
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
19+
*
20+
* @see https://auth0.com/docs/api/management/v2#!/keys/post-encryption-rekey
21+
*/
22+
public function postEncryptionRekey(
23+
?RequestOptions $options = null,
24+
): ResponseInterface;
25+
}

Diff for: tests/Unit/API/Management/KeysTest.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Auth0\SDK\Exception\ArgumentException;
6+
use Auth0\SDK\Configuration\SdkConfiguration;
7+
use Auth0\SDK\Utility\HttpClient;
8+
use Auth0\SDK\Utility\HttpRequest;
9+
use Auth0\SDK\Utility\HttpResponse;
10+
use Auth0\Tests\Utilities\HttpResponseGenerator;
11+
use Auth0\Tests\Utilities\MockDomain;
12+
13+
uses()->group('management', 'management.keys');
14+
15+
beforeEach(function(): void {
16+
$this->config = new SdkConfiguration([
17+
'domain' => MockDomain::valid(),
18+
'cookieSecret' => uniqid(),
19+
'clientId' => uniqid(),
20+
'redirectUri' => uniqid()
21+
]);
22+
23+
$this->client = new HttpClient($this->config, HttpClient::CONTEXT_MANAGEMENT_CLIENT);
24+
$this->endpoint = $this->api->mock()->keys();
25+
});
26+
27+
test('postEncryptionRekey() issues an appropriate request', function(): void {
28+
29+
$this->endpoint->postEncryptionRekey();
30+
31+
expect($this->api->getRequestMethod())->toEqual('POST');
32+
expect($this->api->getRequestUrl())->toEndWith('/api/v2/keys/encryption/rekey');
33+
34+
$headers = $this->api->getRequestHeaders();
35+
expect($headers['Content-Type'][0])->toEqual('application/json');
36+
});
37+
38+
test('postEncryptionRekey() returns 204 on success', function(): void {
39+
40+
// Mocked the API response for successful rekey with status 204
41+
$this->httpResponse204 = HttpResponseGenerator::create('success', 204);
42+
43+
// Mocked the client to return the mocked 204 response
44+
$this->client->mockResponse($this->httpResponse204);
45+
$response = $this->client->method('post')
46+
->addPath(['keys', 'encryption', 'rekey'])
47+
->call();
48+
expect($response->getStatusCode())->toEqual(204);
49+
});

0 commit comments

Comments
 (0)