StsClient.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Aws\Sts;
  3. use Aws\AwsClient;
  4. use Aws\Result;
  5. use Aws\Credentials\Credentials;
  6. /**
  7. * This client is used to interact with the **AWS Security Token Service (AWS STS)**.
  8. *
  9. * @method \Aws\Result assumeRole(array $args = [])
  10. * @method \GuzzleHttp\Promise\Promise assumeRoleAsync(array $args = [])
  11. * @method \Aws\Result assumeRoleWithSAML(array $args = [])
  12. * @method \GuzzleHttp\Promise\Promise assumeRoleWithSAMLAsync(array $args = [])
  13. * @method \Aws\Result assumeRoleWithWebIdentity(array $args = [])
  14. * @method \GuzzleHttp\Promise\Promise assumeRoleWithWebIdentityAsync(array $args = [])
  15. * @method \Aws\Result decodeAuthorizationMessage(array $args = [])
  16. * @method \GuzzleHttp\Promise\Promise decodeAuthorizationMessageAsync(array $args = [])
  17. * @method \Aws\Result getCallerIdentity(array $args = [])
  18. * @method \GuzzleHttp\Promise\Promise getCallerIdentityAsync(array $args = [])
  19. * @method \Aws\Result getFederationToken(array $args = [])
  20. * @method \GuzzleHttp\Promise\Promise getFederationTokenAsync(array $args = [])
  21. * @method \Aws\Result getSessionToken(array $args = [])
  22. * @method \GuzzleHttp\Promise\Promise getSessionTokenAsync(array $args = [])
  23. */
  24. class StsClient extends AwsClient
  25. {
  26. /**
  27. * Creates credentials from the result of an STS operations
  28. *
  29. * @param Result $result Result of an STS operation
  30. *
  31. * @return Credentials
  32. * @throws \InvalidArgumentException if the result contains no credentials
  33. */
  34. public function createCredentials(Result $result)
  35. {
  36. if (!$result->hasKey('Credentials')) {
  37. throw new \InvalidArgumentException('Result contains no credentials');
  38. }
  39. $c = $result['Credentials'];
  40. return new Credentials(
  41. $c['AccessKeyId'],
  42. $c['SecretAccessKey'],
  43. isset($c['SessionToken']) ? $c['SessionToken'] : null,
  44. isset($c['Expiration']) && $c['Expiration'] instanceof \DateTimeInterface
  45. ? (int) $c['Expiration']->format('U')
  46. : null
  47. );
  48. }
  49. }