-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CognitoIdentityProvider RevokeToken * Update CognitoIdentityProvider/CHANGELOG.md
- Loading branch information
Showing
9 changed files
with
314 additions
and
0 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
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,22 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
||
/** | ||
* Exception that is thrown when the request isn't authorized. This can happen due to an invalid access token in the | ||
* request. | ||
*/ | ||
final class UnauthorizedException extends ClientException | ||
{ | ||
protected function populateResult(ResponseInterface $response): void | ||
{ | ||
$data = $response->toArray(false); | ||
|
||
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) { | ||
$this->message = $v; | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
||
/** | ||
* Exception that is thrown when you attempt to perform an operation that isn't enabled for the user pool client. | ||
*/ | ||
final class UnsupportedOperationException extends ClientException | ||
{ | ||
protected function populateResult(ResponseInterface $response): void | ||
{ | ||
$data = $response->toArray(false); | ||
|
||
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) { | ||
$this->message = $v; | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
||
/** | ||
* Exception that is thrown when an unsupported token is passed to an operation. | ||
*/ | ||
final class UnsupportedTokenTypeException extends ClientException | ||
{ | ||
protected function populateResult(ResponseInterface $response): void | ||
{ | ||
$data = $response->toArray(false); | ||
|
||
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) { | ||
$this->message = $v; | ||
} | ||
} | ||
} |
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,136 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Input; | ||
|
||
use AsyncAws\Core\Exception\InvalidArgument; | ||
use AsyncAws\Core\Input; | ||
use AsyncAws\Core\Request; | ||
use AsyncAws\Core\Stream\StreamFactory; | ||
|
||
final class RevokeTokenRequest extends Input | ||
{ | ||
/** | ||
* The refresh token that you want to revoke. | ||
* | ||
* @required | ||
* | ||
* @var string|null | ||
*/ | ||
private $token; | ||
|
||
/** | ||
* The client ID for the token that you want to revoke. | ||
* | ||
* @required | ||
* | ||
* @var string|null | ||
*/ | ||
private $clientId; | ||
|
||
/** | ||
* The secret for the client ID. This is required only if the client ID has a secret. | ||
* | ||
* @var string|null | ||
*/ | ||
private $clientSecret; | ||
|
||
/** | ||
* @param array{ | ||
* Token?: string, | ||
* ClientId?: string, | ||
* ClientSecret?: string, | ||
* @region?: string, | ||
* } $input | ||
*/ | ||
public function __construct(array $input = []) | ||
{ | ||
$this->token = $input['Token'] ?? null; | ||
$this->clientId = $input['ClientId'] ?? null; | ||
$this->clientSecret = $input['ClientSecret'] ?? null; | ||
parent::__construct($input); | ||
} | ||
|
||
public static function create($input): self | ||
{ | ||
return $input instanceof self ? $input : new self($input); | ||
} | ||
|
||
public function getClientId(): ?string | ||
{ | ||
return $this->clientId; | ||
} | ||
|
||
public function getClientSecret(): ?string | ||
{ | ||
return $this->clientSecret; | ||
} | ||
|
||
public function getToken(): ?string | ||
{ | ||
return $this->token; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function request(): Request | ||
{ | ||
// Prepare headers | ||
$headers = [ | ||
'Content-Type' => 'application/x-amz-json-1.1', | ||
'X-Amz-Target' => 'AWSCognitoIdentityProviderService.RevokeToken', | ||
]; | ||
|
||
// Prepare query | ||
$query = []; | ||
|
||
// Prepare URI | ||
$uriString = '/'; | ||
|
||
// Prepare Body | ||
$bodyPayload = $this->requestBody(); | ||
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304); | ||
|
||
// Return the Request | ||
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body)); | ||
} | ||
|
||
public function setClientId(?string $value): self | ||
{ | ||
$this->clientId = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function setClientSecret(?string $value): self | ||
{ | ||
$this->clientSecret = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function setToken(?string $value): self | ||
{ | ||
$this->token = $value; | ||
|
||
return $this; | ||
} | ||
|
||
private function requestBody(): array | ||
{ | ||
$payload = []; | ||
if (null === $v = $this->token) { | ||
throw new InvalidArgument(sprintf('Missing parameter "Token" for "%s". The value cannot be null.', __CLASS__)); | ||
} | ||
$payload['Token'] = $v; | ||
if (null === $v = $this->clientId) { | ||
throw new InvalidArgument(sprintf('Missing parameter "ClientId" for "%s". The value cannot be null.', __CLASS__)); | ||
} | ||
$payload['ClientId'] = $v; | ||
if (null !== $v = $this->clientSecret) { | ||
$payload['ClientSecret'] = $v; | ||
} | ||
|
||
return $payload; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Result; | ||
|
||
use AsyncAws\Core\Result; | ||
|
||
class RevokeTokenResponse extends Result | ||
{ | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Tests\Unit\Input; | ||
|
||
use AsyncAws\CognitoIdentityProvider\Input\RevokeTokenRequest; | ||
use AsyncAws\Core\Test\TestCase; | ||
|
||
class RevokeTokenRequestTest extends TestCase | ||
{ | ||
public function testRequest(): void | ||
{ | ||
$input = new RevokeTokenRequest([ | ||
'Token' => 'refresh_token', | ||
'ClientId' => 'client_id', | ||
'ClientSecret' => 'client_secret', | ||
]); | ||
|
||
// see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_RevokeToken.html | ||
$expected = ' | ||
POST / HTTP/1.0 | ||
Content-Type: application/x-amz-json-1.1 | ||
X-AMZ-Target: AWSCognitoIdentityProviderService.RevokeToken | ||
{ | ||
"Token": "refresh_token", | ||
"ClientId": "client_id", | ||
"ClientSecret": "client_secret" | ||
} | ||
'; | ||
|
||
self::assertRequestEqualsHttpRequest($expected, $input->request()); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace AsyncAws\CognitoIdentityProvider\Tests\Unit\Result; | ||
|
||
use AsyncAws\CognitoIdentityProvider\Result\RevokeTokenResponse; | ||
use AsyncAws\Core\Response; | ||
use AsyncAws\Core\Test\Http\SimpleMockedResponse; | ||
use AsyncAws\Core\Test\TestCase; | ||
use Psr\Log\NullLogger; | ||
use Symfony\Component\HttpClient\MockHttpClient; | ||
|
||
class RevokeTokenResponseTest extends TestCase | ||
{ | ||
public function testRevokeTokenResponse(): void | ||
{ | ||
self::markTestSkipped('The response has no body to test'); | ||
|
||
// see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_RevokeToken.html | ||
$response = new SimpleMockedResponse('{}'); | ||
|
||
$client = new MockHttpClient($response); | ||
$result = new RevokeTokenResponse(new Response($client->request('POST', 'http://localhost'), $client, new NullLogger())); | ||
} | ||
} |