-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00788c5
commit 1aa0008
Showing
7 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |