-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Showing
22 changed files
with
743 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,29 @@ | ||
--- | ||
layout: client | ||
category: clients | ||
name: SSO | ||
package: async-aws/core | ||
fqcn: AsyncAws\Core\Sso\SsoClient | ||
--- | ||
|
||
## Usage | ||
|
||
### Retrieve role credentials | ||
|
||
```php | ||
use AsyncAws\Core\Sso\Input\GetRoleCredentialsRequest; | ||
use AsyncAws\Core\Sso\SsoClient; | ||
|
||
$client = new StsClient(); | ||
|
||
$result = $client->getRoleCredentials(new GetRoleCredentialsRequest([ | ||
'roleName' => 'YourRoleName', | ||
'accountId' => 'YourAccountId', | ||
'accessToken' => 'YourAccessToken', | ||
])); | ||
|
||
echo 'AccessKeyId:' . $result->getRoleCredentials()->getAccessKeyId().PHP_EOL; | ||
echo 'Expiration:' . $result->getRoleCredentials()->getExpiration().PHP_EOL; | ||
echo 'SecretAccessKey:' . $result->getRoleCredentials()->getSecretAccessKey().PHP_EOL; | ||
echo 'SessionToken:' . $result->getRoleCredentials()->getSessionToken(); | ||
``` |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
### Added | ||
|
||
- Support for LocationService | ||
- Support for SSO credentials | ||
|
||
## 1.19.0 | ||
|
||
|
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
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,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AsyncAws\Core\Credentials; | ||
|
||
use AsyncAws\Core\EnvVar; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
|
||
/** | ||
* Load and parse AWS SSO cache file. | ||
*/ | ||
final class SsoCacheFileLoader | ||
{ | ||
public const KEY_ACCESS_TOKEN = 'accessToken'; | ||
public const KEY_EXPIRES_AT = 'expiresAt'; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
public function __construct(?LoggerInterface $logger = null) | ||
{ | ||
$this->logger = $logger ?? new NullLogger(); | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function loadSsoCacheFile(string $ssoStartUrl): array | ||
{ | ||
$filepath = sprintf('%s/.aws/sso/cache/%s.json', $this->getHomeDir(), sha1($ssoStartUrl)); | ||
|
||
if (!@is_readable($filepath)) { | ||
$this->logger->warning('The sso cache file {path} is not readable.', ['path' => $filepath]); | ||
|
||
return []; | ||
} | ||
|
||
$tokenData = json_decode(file_get_contents($filepath), true); | ||
if (!isset($tokenData[self::KEY_ACCESS_TOKEN], $tokenData[self::KEY_EXPIRES_AT])) { | ||
$this->logger->warning('Token file at {path} must contain an accessToken and an expiresAt.', ['path' => $filepath]); | ||
|
||
return []; | ||
} | ||
|
||
try { | ||
$expiration = (new \DateTimeImmutable($tokenData[self::KEY_EXPIRES_AT])); | ||
} catch (\Exception $e) { | ||
$this->logger->warning('Cached SSO credentials returned an invalid expiresAt value.'); | ||
|
||
return []; | ||
} | ||
|
||
if ($expiration < new \DateTimeImmutable()) { | ||
$this->logger->warning('Cached SSO credentials returned an invalid expiresAt value.'); | ||
|
||
return []; | ||
} | ||
|
||
return $tokenData; | ||
} | ||
|
||
private function getHomeDir(): string | ||
{ | ||
// On Linux/Unix-like systems, use the HOME environment variable | ||
if (null !== $homeDir = EnvVar::get('HOME')) { | ||
return $homeDir; | ||
} | ||
|
||
// Get the HOMEDRIVE and HOMEPATH values for Windows hosts | ||
$homeDrive = EnvVar::get('HOMEDRIVE'); | ||
$homePath = EnvVar::get('HOMEPATH'); | ||
|
||
return ($homeDrive && $homePath) ? $homeDrive . $homePath : '/'; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Core\Sso\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
|
||
/** | ||
* Indicates that a problem occurred with the input to the request. For example, a required parameter might be missing | ||
* or out of range. | ||
*/ | ||
final class InvalidRequestException extends ClientException | ||
{ | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Core\Sso\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
|
||
/** | ||
* The specified resource doesn't exist. | ||
*/ | ||
final class ResourceNotFoundException extends ClientException | ||
{ | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Core\Sso\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
|
||
/** | ||
* Indicates that the request is being made too frequently and is more than what the server can handle. | ||
*/ | ||
final class TooManyRequestsException extends ClientException | ||
{ | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Core\Sso\Exception; | ||
|
||
use AsyncAws\Core\Exception\Http\ClientException; | ||
|
||
/** | ||
* Indicates that the request is not authorized. This can happen due to an invalid access token in the request. | ||
*/ | ||
final class UnauthorizedException extends ClientException | ||
{ | ||
} |
Oops, something went wrong.