From 1aa0008c0a8e3ca62384923af8775d8be1b0d9b4 Mon Sep 17 00:00:00 2001 From: Snehil Kishore Date: Sun, 12 Jan 2025 21:47:22 +0530 Subject: [PATCH] Adding Additional Endpoints --- src/API/Management.php | 14 +++++- src/API/Management/RefreshTokens.php | 50 +++++++++++++++++++ src/API/Management/Sessions.php | 50 +++++++++++++++++++ .../API/Management/RefreshTokensInterface.php | 46 +++++++++++++++++ .../API/Management/SessionsInterface.php | 46 +++++++++++++++++ .../Unit/API/Management/RefreshTokensTest.php | 30 +++++++++++ tests/Unit/API/Management/SessionsTest.php | 30 +++++++++++ 7 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 src/API/Management/RefreshTokens.php create mode 100644 src/API/Management/Sessions.php create mode 100644 src/Contract/API/Management/RefreshTokensInterface.php create mode 100644 src/Contract/API/Management/SessionsInterface.php create mode 100644 tests/Unit/API/Management/RefreshTokensTest.php create mode 100644 tests/Unit/API/Management/SessionsTest.php diff --git a/src/API/Management.php b/src/API/Management.php index 1e3c5f79..5ca1debe 100644 --- a/src/API/Management.php +++ b/src/API/Management.php @@ -4,9 +4,9 @@ namespace Auth0\SDK\API; -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}; +use Auth0\SDK\API\Management\{Actions, AttackProtection, Blacklists, ClientGrants, Clients, Connections, DeviceCredentials, EmailTemplates, Emails, Grants, Guardian, Jobs, Keys, LogStreams, Logs, Organizations, RefreshTokens, ResourceServers, Roles, Rules, Sessions, Stats, Tenants, Tickets, UserBlocks, Users, UsersByEmail}; use Auth0\SDK\Configuration\SdkConfiguration; -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}; +use Auth0\SDK\Contract\API\Management\{ActionsInterface, AttackProtectionInterface, BlacklistsInterface, ClientGrantsInterface, ClientsInterface, ConnectionsInterface, DeviceCredentialsInterface, EmailTemplatesInterface, EmailsInterface, GrantsInterface, GuardianInterface, JobsInterface, KeysInterface, LogStreamsInterface, LogsInterface, OrganizationsInterface, RefreshTokensInterface, ResourceServersInterface, RolesInterface, RulesInterface, SessionsInterface, StatsInterface, TenantsInterface, TicketsInterface, UserBlocksInterface, UsersByEmailInterface, UsersInterface}; use Auth0\SDK\Contract\API\{AuthenticationInterface, ManagementInterface}; use Auth0\SDK\Utility\{HttpClient, HttpResponse, HttpResponsePaginator}; use Psr\Cache\CacheItemPoolInterface; @@ -202,6 +202,11 @@ public function organizations(): OrganizationsInterface return Organizations::instance($this->getHttpClient()); } + public function refreshTokens(): RefreshTokensInterface + { + return RefreshTokens::instance($this->getHttpClient()); + } + public function resourceServers(): ResourceServersInterface { return ResourceServers::instance($this->getHttpClient()); @@ -217,6 +222,11 @@ public function rules(): RulesInterface return Rules::instance($this->getHttpClient()); } + public function sessions(): SessionsInterface + { + return Sessions::instance($this->getHttpClient()); + } + public function stats(): StatsInterface { return Stats::instance($this->getHttpClient()); diff --git a/src/API/Management/RefreshTokens.php b/src/API/Management/RefreshTokens.php new file mode 100644 index 00000000..94c32396 --- /dev/null +++ b/src/API/Management/RefreshTokens.php @@ -0,0 +1,50 @@ +string()->trim(); + + Toolkit::assert([ + [$id, \Auth0\SDK\Exception\ArgumentException::missing('id')], + ])->isString(); + + return $this->getHttpClient() + ->method('delete')->addPath(['refresh-tokens', $id]) + ->withOptions($options) + ->call(); + } + + public function get( + string $id, + ?RequestOptions $options = null, + ): ResponseInterface { + [$id] = Toolkit::filter([$id])->string()->trim(); + + Toolkit::assert([ + [$id, \Auth0\SDK\Exception\ArgumentException::missing('id')], + ])->isString(); + + return $this->getHttpClient() + ->method('get')->addPath(['refresh-tokens', $id]) + ->withOptions($options) + ->call(); + } +} diff --git a/src/API/Management/Sessions.php b/src/API/Management/Sessions.php new file mode 100644 index 00000000..f570aeb6 --- /dev/null +++ b/src/API/Management/Sessions.php @@ -0,0 +1,50 @@ +string()->trim(); + + Toolkit::assert([ + [$id, \Auth0\SDK\Exception\ArgumentException::missing('id')], + ])->isString(); + + return $this->getHttpClient() + ->method('delete')->addPath(['sessions', $id]) + ->withOptions($options) + ->call(); + } + + public function get( + string $id, + ?RequestOptions $options = null, + ): ResponseInterface { + [$id] = Toolkit::filter([$id])->string()->trim(); + + Toolkit::assert([ + [$id, \Auth0\SDK\Exception\ArgumentException::missing('id')], + ])->isString(); + + return $this->getHttpClient() + ->method('get')->addPath(['sessions', $id]) + ->withOptions($options) + ->call(); + } +} diff --git a/src/Contract/API/Management/RefreshTokensInterface.php b/src/Contract/API/Management/RefreshTokensInterface.php new file mode 100644 index 00000000..e273f827 --- /dev/null +++ b/src/Contract/API/Management/RefreshTokensInterface.php @@ -0,0 +1,46 @@ +group('management', 'management.refresh_tokens'); + +beforeEach(function(): void { + $this->endpoint = $this->api->mock()->refreshTokens(); +}); + +test('get() issues an appropriate request', function(): void { + $id = uniqid(); + + $this->endpoint->get($id); + + expect($this->api->getRequestMethod())->toEqual('GET'); + expect($this->api->getRequestUrl())->toEndWith('/api/v2/refresh-tokens/' . $id); +}); + +test('delete() issues an appropriate request', function(): void { + $id = uniqid(); + + $this->endpoint->delete($id); + + expect($this->api->getRequestMethod())->toEqual('DELETE'); + expect($this->api->getRequestUrl())->toEndWith('/api/v2/refresh-tokens/' . $id); + + $headers = $this->api->getRequestHeaders(); + expect($headers['Content-Type'][0])->toEqual('application/json'); +}); \ No newline at end of file diff --git a/tests/Unit/API/Management/SessionsTest.php b/tests/Unit/API/Management/SessionsTest.php new file mode 100644 index 00000000..4c7a1ab9 --- /dev/null +++ b/tests/Unit/API/Management/SessionsTest.php @@ -0,0 +1,30 @@ +group('management', 'management.sessions'); + +beforeEach(function(): void { + $this->endpoint = $this->api->mock()->sessions(); +}); + +test('get() issues an appropriate request', function(): void { + $id = uniqid(); + + $this->endpoint->get($id); + + expect($this->api->getRequestMethod())->toEqual('GET'); + expect($this->api->getRequestUrl())->toEndWith('/api/v2/sessions/' . $id); +}); + +test('delete() issues an appropriate request', function(): void { + $id = uniqid(); + + $this->endpoint->delete($id); + + expect($this->api->getRequestMethod())->toEqual('DELETE'); + expect($this->api->getRequestUrl())->toEndWith('/api/v2/sessions/' . $id); + + $headers = $this->api->getRequestHeaders(); + expect($headers['Content-Type'][0])->toEqual('application/json'); +}); \ No newline at end of file