Skip to content

Commit

Permalink
Adding Additional Endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore7snehil committed Jan 12, 2025
1 parent 00788c5 commit 1aa0008
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/API/Management.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
50 changes: 50 additions & 0 deletions src/API/Management/RefreshTokens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Auth0\SDK\API\Management;

use Auth0\SDK\Contract\API\Management\RefreshTokensInterface;
use Auth0\SDK\Utility\Request\RequestOptions;
use Auth0\SDK\Utility\Toolkit;
use Psr\Http\Message\ResponseInterface;

/**
* Handles requests to the Refresh Tokens endpoint of the v2 Management API.
*
* @see https://auth0.com/docs/api/management/v2#!/Refresh_Tokens
*/
final class RefreshTokens extends ManagementEndpoint implements RefreshTokensInterface
{
public function delete(
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('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();
}
}
50 changes: 50 additions & 0 deletions src/API/Management/Sessions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Auth0\SDK\API\Management;

use Auth0\SDK\Contract\API\Management\SessionsInterface;
use Auth0\SDK\Utility\Request\RequestOptions;
use Auth0\SDK\Utility\Toolkit;
use Psr\Http\Message\ResponseInterface;

/**
* Handles requests to the Sessions endpoint of the v2 Management API.
*
* @see https://auth0.com/docs/api/management/v2/Sessions
*/
final class Sessions extends ManagementEndpoint implements SessionsInterface
{
public function delete(
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('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();
}
}
46 changes: 46 additions & 0 deletions src/Contract/API/Management/RefreshTokensInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Auth0\SDK\Contract\API\Management;

use Auth0\SDK\Utility\Request\RequestOptions;
use Psr\Http\Message\ResponseInterface;

interface RefreshTokensInterface
{
/**
* Delete a Refresh Token by ID.
* Required scope: `delete:refresh_tokens`.
*
* @param string $id ID of the refresh token to delete.
* @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.)
*
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
*
* @see https://auth0.com/docs/api/management/v2#!/Refresh_Tokens/delete_refresh_token
*/
public function delete(
string $id,
?RequestOptions $options = null,
): ResponseInterface;

/**
* Retrieve Refresh Token information
* Required scopes:
* - `read:refresh_tokens` for any call to this endpoint.
*
* @param string $id ID of refresh token to retrieve
* @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.)
*
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
*
* @see https://auth0.com/docs/api/management/v2#!/Refresh_Tokens/get_refresh_token
*/
public function get(
string $id,
?RequestOptions $options = null,
): ResponseInterface;
}
46 changes: 46 additions & 0 deletions src/Contract/API/Management/SessionsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Auth0\SDK\Contract\API\Management;

use Auth0\SDK\Utility\Request\RequestOptions;
use Psr\Http\Message\ResponseInterface;

interface SessionsInterface
{
/**
* Delete a Session by ID.
* Required scope: `delete:sessions`.
*
* @param string $id ID of the session to delete.
* @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.)
*
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
*
* @see https://auth0.com/docs/api/management/v2#!/Sessions/delete_session
*/
public function delete(
string $id,
?RequestOptions $options = null,
): ResponseInterface;

/**
* Retrieve Session information
* Required scopes:
* - `read:sessions` for any call to this endpoint.
*
* @param string $id ID of session to retrieve
* @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.)
*
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
*
* @see https://auth0.com/docs/api/management/v2#!/Sessions/get_session
*/
public function get(
string $id,
?RequestOptions $options = null,
): ResponseInterface;
}
30 changes: 30 additions & 0 deletions tests/Unit/API/Management/RefreshTokensTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

uses()->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');
});
30 changes: 30 additions & 0 deletions tests/Unit/API/Management/SessionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

uses()->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');
});

0 comments on commit 1aa0008

Please sign in to comment.