-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds support for SSO credentials (#1519)
adds support for sso credentials
- Loading branch information
Showing
39 changed files
with
1,049 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
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/sso | ||
fqcn: AsyncAws\Sso\SsoClient | ||
--- | ||
|
||
## Usage | ||
|
||
### Retrieve role credentials | ||
|
||
```php | ||
use AsyncAws\Sso\Input\GetRoleCredentialsRequest; | ||
use AsyncAws\Sso\SsoClient; | ||
|
||
$client = new SsoClient(); | ||
|
||
$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
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 (false === ($contents = @file_get_contents($filepath))) { | ||
$this->logger->warning('The sso cache file {path} is not readable.', ['path' => $filepath]); | ||
|
||
return []; | ||
} | ||
|
||
$tokenData = json_decode($contents, 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
### Added | ||
|
||
- Support for LocationService | ||
- Support for SSO | ||
|
||
## 1.11.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
/.gitignore export-ignore | ||
/Makefile export-ignore | ||
/phpunit.xml.dist export-ignore |
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,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [nyholm, jderusse] |
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,2 @@ | ||
[*.yml] | ||
indent_size = 2 |
Oops, something went wrong.