StsCredential.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace AlibabaCloud\Credentials;
  3. use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
  4. /**
  5. * Use the STS Token to complete the authentication.
  6. */
  7. class StsCredential implements CredentialsInterface
  8. {
  9. /**
  10. * @var string
  11. */
  12. private $accessKeyId;
  13. /**
  14. * @var string
  15. */
  16. private $accessKeySecret;
  17. /**
  18. * @var string
  19. */
  20. private $securityToken;
  21. /**
  22. * @var int
  23. */
  24. private $expiration;
  25. /**
  26. * StsCredential constructor.
  27. *
  28. * @param string $access_key_id Access key ID
  29. * @param string $access_key_secret Access Key Secret
  30. * @param int $expiration
  31. * @param string $security_token Security Token
  32. */
  33. public function __construct($access_key_id, $access_key_secret, $expiration, $security_token = '')
  34. {
  35. Filter::accessKey($access_key_id, $access_key_secret);
  36. Filter::expiration($expiration);
  37. $this->accessKeyId = $access_key_id;
  38. $this->accessKeySecret = $access_key_secret;
  39. $this->expiration = $expiration;
  40. $this->securityToken = $security_token;
  41. }
  42. /**
  43. * @return int
  44. */
  45. public function getExpiration()
  46. {
  47. return $this->expiration;
  48. }
  49. /**
  50. * @return string
  51. */
  52. public function getAccessKeyId()
  53. {
  54. return $this->accessKeyId;
  55. }
  56. /**
  57. * @return string
  58. */
  59. public function getAccessKeySecret()
  60. {
  61. return $this->accessKeySecret;
  62. }
  63. /**
  64. * @return string
  65. */
  66. public function getSecurityToken()
  67. {
  68. return $this->securityToken;
  69. }
  70. /**
  71. * @return string
  72. */
  73. public function __toString()
  74. {
  75. return "$this->accessKeyId#$this->accessKeySecret#$this->securityToken";
  76. }
  77. /**
  78. * @return ShaHmac1Signature
  79. */
  80. public function getSignature()
  81. {
  82. return new ShaHmac1Signature();
  83. }
  84. }