Skip to content

Commit f54ca47

Browse files
Adding Support For Session And Refresh Tokens (#786)
### Changes Support Added for following endpoints: - [api/management/v2/users/get-refresh-tokens-for-user](https://auth0.com/docs/api/management/v2/users/get-refresh-tokens-for-user) - [api/management/v2/users/delete-refresh-tokens-for-user](https://auth0.com/docs/api/management/v2/users/delete-refresh-tokens-for-user) - [api/management/v2/users/get-sessions-for-user](https://auth0.com/docs/api/management/v2/users/get-sessions-for-user) - [api/management/v2/users/delete-sessions-for-user](https://auth0.com/docs/api/management/v2/users/delete-sessions-for-user) - [api/management/v2/refresh-tokens/get-refresh-token](https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token) - [api/management/v2/refresh-tokens/delete-refresh-token](https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token) - [api/management/v2/sessions/get-session](https://auth0.com/docs/api/management/v2/sessions/get-session) - [api/management/v2/sessions/delete-session](https://auth0.com/docs/api/management/v2/sessions/delete-session) ### References - [api/management/v2/users/get-refresh-tokens-for-user](https://auth0.com/docs/api/management/v2/users/get-refresh-tokens-for-user) - [api/management/v2/users/delete-refresh-tokens-for-user](https://auth0.com/docs/api/management/v2/users/delete-refresh-tokens-for-user) - [api/management/v2/users/get-sessions-for-user](https://auth0.com/docs/api/management/v2/users/get-sessions-for-user) - [api/management/v2/users/delete-sessions-for-user](https://auth0.com/docs/api/management/v2/users/delete-sessions-for-user) - [api/management/v2/refresh-tokens/get-refresh-token](https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token) - [api/management/v2/refresh-tokens/delete-refresh-token](https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token) - [api/management/v2/sessions/get-session](https://auth0.com/docs/api/management/v2/sessions/get-session) - [api/management/v2/sessions/delete-session](https://auth0.com/docs/api/management/v2/sessions/delete-session) ### 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 3acf0f4 commit f54ca47

File tree

10 files changed

+436
-2
lines changed

10 files changed

+436
-2
lines changed

src/API/Management.php

+12-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, Keys, 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, RefreshTokens, ResourceServers, Roles, Rules, Sessions, 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, KeysInterface, 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, RefreshTokensInterface, ResourceServersInterface, RolesInterface, RulesInterface, SessionsInterface, 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;
@@ -202,6 +202,11 @@ public function organizations(): OrganizationsInterface
202202
return Organizations::instance($this->getHttpClient());
203203
}
204204

205+
public function refreshTokens(): RefreshTokensInterface
206+
{
207+
return RefreshTokens::instance($this->getHttpClient());
208+
}
209+
205210
public function resourceServers(): ResourceServersInterface
206211
{
207212
return ResourceServers::instance($this->getHttpClient());
@@ -217,6 +222,11 @@ public function rules(): RulesInterface
217222
return Rules::instance($this->getHttpClient());
218223
}
219224

225+
public function sessions(): SessionsInterface
226+
{
227+
return Sessions::instance($this->getHttpClient());
228+
}
229+
220230
public function stats(): StatsInterface
221231
{
222232
return Stats::instance($this->getHttpClient());

src/API/Management/RefreshTokens.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Auth0\SDK\API\Management;
6+
7+
use Auth0\SDK\Contract\API\Management\RefreshTokensInterface;
8+
use Auth0\SDK\Utility\Request\RequestOptions;
9+
use Auth0\SDK\Utility\Toolkit;
10+
use Psr\Http\Message\ResponseInterface;
11+
12+
/**
13+
* Handles requests to the Refresh Tokens endpoint of the v2 Management API.
14+
*
15+
* @see https://auth0.com/docs/api/management/v2#!/Refresh_Tokens
16+
*/
17+
final class RefreshTokens extends ManagementEndpoint implements RefreshTokensInterface
18+
{
19+
public function delete(
20+
string $id,
21+
?RequestOptions $options = null,
22+
): ResponseInterface {
23+
[$id] = Toolkit::filter([$id])->string()->trim();
24+
25+
Toolkit::assert([
26+
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
27+
])->isString();
28+
29+
return $this->getHttpClient()
30+
->method('delete')->addPath(['refresh-tokens', $id])
31+
->withOptions($options)
32+
->call();
33+
}
34+
35+
public function get(
36+
string $id,
37+
?RequestOptions $options = null,
38+
): ResponseInterface {
39+
[$id] = Toolkit::filter([$id])->string()->trim();
40+
41+
Toolkit::assert([
42+
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
43+
])->isString();
44+
45+
return $this->getHttpClient()
46+
->method('get')->addPath(['refresh-tokens', $id])
47+
->withOptions($options)
48+
->call();
49+
}
50+
}

src/API/Management/Sessions.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Auth0\SDK\API\Management;
6+
7+
use Auth0\SDK\Contract\API\Management\SessionsInterface;
8+
use Auth0\SDK\Utility\Request\RequestOptions;
9+
use Auth0\SDK\Utility\Toolkit;
10+
use Psr\Http\Message\ResponseInterface;
11+
12+
/**
13+
* Handles requests to the Sessions endpoint of the v2 Management API.
14+
*
15+
* @see https://auth0.com/docs/api/management/v2/Sessions
16+
*/
17+
final class Sessions extends ManagementEndpoint implements SessionsInterface
18+
{
19+
public function delete(
20+
string $id,
21+
?RequestOptions $options = null,
22+
): ResponseInterface {
23+
[$id] = Toolkit::filter([$id])->string()->trim();
24+
25+
Toolkit::assert([
26+
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
27+
])->isString();
28+
29+
return $this->getHttpClient()
30+
->method('delete')->addPath(['sessions', $id])
31+
->withOptions($options)
32+
->call();
33+
}
34+
35+
public function get(
36+
string $id,
37+
?RequestOptions $options = null,
38+
): ResponseInterface {
39+
[$id] = Toolkit::filter([$id])->string()->trim();
40+
41+
Toolkit::assert([
42+
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
43+
])->isString();
44+
45+
return $this->getHttpClient()
46+
->method('get')->addPath(['sessions', $id])
47+
->withOptions($options)
48+
->call();
49+
}
50+
}

src/API/Management/Users.php

+64
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,38 @@ public function deleteMultifactorProvider(
221221
->call();
222222
}
223223

224+
public function deleteRefreshTokens(
225+
string $user,
226+
?RequestOptions $options = null,
227+
): ResponseInterface {
228+
[$user] = Toolkit::filter([$user])->string()->trim();
229+
230+
Toolkit::assert([
231+
[$user, \Auth0\SDK\Exception\ArgumentException::missing('user')],
232+
])->isString();
233+
234+
return $this->getHttpClient()
235+
->method('delete')->addPath(['users', $user, 'refresh-tokens'])
236+
->withOptions($options)
237+
->call();
238+
}
239+
240+
public function deleteSessions(
241+
string $user,
242+
?RequestOptions $options = null,
243+
): ResponseInterface {
244+
[$user] = Toolkit::filter([$user])->string()->trim();
245+
246+
Toolkit::assert([
247+
[$user, \Auth0\SDK\Exception\ArgumentException::missing('user')],
248+
])->isString();
249+
250+
return $this->getHttpClient()
251+
->method('delete')->addPath(['users', $user, 'sessions'])
252+
->withOptions($options)
253+
->call();
254+
}
255+
224256
public function get(
225257
string $id,
226258
?RequestOptions $options = null,
@@ -351,6 +383,22 @@ public function getPermissions(
351383
->call();
352384
}
353385

386+
public function getRefreshTokens(
387+
string $id,
388+
?RequestOptions $options = null,
389+
): ResponseInterface {
390+
[$id] = Toolkit::filter([$id])->string()->trim();
391+
392+
Toolkit::assert([
393+
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
394+
])->isString();
395+
396+
return $this->getHttpClient()
397+
->method('get')->addPath(['users', $id, 'refresh-tokens'])
398+
->withOptions($options)
399+
->call();
400+
}
401+
354402
public function getRoles(
355403
string $id,
356404
?RequestOptions $options = null,
@@ -367,6 +415,22 @@ public function getRoles(
367415
->call();
368416
}
369417

418+
public function getSessions(
419+
string $id,
420+
?RequestOptions $options = null,
421+
): ResponseInterface {
422+
[$id] = Toolkit::filter([$id])->string()->trim();
423+
424+
Toolkit::assert([
425+
[$id, \Auth0\SDK\Exception\ArgumentException::missing('id')],
426+
])->isString();
427+
428+
return $this->getHttpClient()
429+
->method('get')->addPath(['users', $id, 'sessions'])
430+
->withOptions($options)
431+
->call();
432+
}
433+
370434
public function invalidateBrowsers(
371435
string $id,
372436
?RequestOptions $options = null,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 RefreshTokensInterface
11+
{
12+
/**
13+
* Delete a Refresh Token by ID.
14+
* Required scope: `delete:refresh_tokens`.
15+
*
16+
* @param string $id ID of the refresh token to delete.
17+
* @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.)
18+
*
19+
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
20+
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
21+
*
22+
* @see https://auth0.com/docs/api/management/v2#!/Refresh_Tokens/delete_refresh_token
23+
*/
24+
public function delete(
25+
string $id,
26+
?RequestOptions $options = null,
27+
): ResponseInterface;
28+
29+
/**
30+
* Retrieve Refresh Token information
31+
* Required scopes:
32+
* - `read:refresh_tokens` for any call to this endpoint.
33+
*
34+
* @param string $id ID of refresh token to retrieve
35+
* @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.)
36+
*
37+
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
38+
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
39+
*
40+
* @see https://auth0.com/docs/api/management/v2#!/Refresh_Tokens/get_refresh_token
41+
*/
42+
public function get(
43+
string $id,
44+
?RequestOptions $options = null,
45+
): ResponseInterface;
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 SessionsInterface
11+
{
12+
/**
13+
* Delete a Session by ID.
14+
* Required scope: `delete:sessions`.
15+
*
16+
* @param string $id ID of the session to delete.
17+
* @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.)
18+
*
19+
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
20+
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
21+
*
22+
* @see https://auth0.com/docs/api/management/v2#!/Sessions/delete_session
23+
*/
24+
public function delete(
25+
string $id,
26+
?RequestOptions $options = null,
27+
): ResponseInterface;
28+
29+
/**
30+
* Retrieve Session information
31+
* Required scopes:
32+
* - `read:sessions` for any call to this endpoint.
33+
*
34+
* @param string $id ID of session to retrieve
35+
* @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.)
36+
*
37+
* @throws \Auth0\SDK\Exception\ArgumentException when an invalid `id` is provided
38+
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error
39+
*
40+
* @see https://auth0.com/docs/api/management/v2#!/Sessions/get_session
41+
*/
42+
public function get(
43+
string $id,
44+
?RequestOptions $options = null,
45+
): ResponseInterface;
46+
}

0 commit comments

Comments
 (0)