| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Dudlewebs\WPMCS\s3\Aws\Token; |
| 4 | 4 | |
| 5 | 5 | use Dudlewebs\WPMCS\s3\Aws\Identity\BearerTokenIdentity; |
| 6 | -use Dudlewebs\WPMCS\s3\Aws\Token\TokenInterface; | |
| 7 | 6 | /** |
| 8 | 7 | * Basic implementation of the AWS Token interface that allows callers to |
| 9 | 8 | * pass in an AWS token in the constructor. |
| 10 | 9 | */ |
| @@ -11,8 +10,9 @@ | ||
| 11 | 10 | class Token extends BearerTokenIdentity implements TokenInterface, \Serializable |
| 12 | 11 | { |
| 13 | 12 | protected $token; |
| 14 | 13 | protected $expires; |
| 14 | + protected ?TokenSource $source; | |
| 15 | 15 | /** |
| 16 | 16 | * Constructs a new basic token object, with the specified AWS |
| 17 | 17 | * token |
| 18 | 18 | * |
| @@ -18,12 +18,13 @@ | ||
| 18 | 18 | * |
| 19 | 19 | * @param string $token Security token to use |
| 20 | 20 | * @param int $expires UNIX timestamp for when the token expires |
| 21 | 21 | */ |
| 22 | - public function __construct($token, $expires = null) | |
| 22 | + public function __construct($token, $expires = null, ?TokenSource $source = null) | |
| 23 | 23 | { |
| 24 | 24 | $this->token = $token; |
| 25 | 25 | $this->expires = $expires; |
| 26 | + $this->source = $source; | |
| 26 | 27 | } |
| 27 | 28 | /** |
| 28 | 29 | * Sets the state of a token object |
| 29 | 30 | * |
| @@ -47,8 +48,15 @@ | ||
| 47 | 48 | { |
| 48 | 49 | return $this->expires; |
| 49 | 50 | } |
| 50 | 51 | /** |
| 52 | + * @return string|null | |
| 53 | + */ | |
| 54 | + public function getSource() : ?string | |
| 55 | + { | |
| 56 | + return $this->source?->value; | |
| 57 | + } | |
| 58 | + /** | |
| 51 | 59 | * @return bool |
| 52 | 60 | */ |
| 53 | 61 | public function isExpired() |
| 54 | 62 | { |
| @@ -58,9 +66,9 @@ | ||
| 58 | 66 | * @return array |
| 59 | 67 | */ |
| 60 | 68 | public function toArray() |
| 61 | 69 | { |
| 62 | - return ['token' => $this->token, 'expires' => $this->expires]; | |
| 70 | + return ['token' => $this->token, 'expires' => $this->expires, 'source' => $this->source?->value]; | |
| 63 | 71 | } |
| 64 | 72 | /** |
| 65 | 73 | * @return string |
| 66 | 74 | */ |
| @@ -89,6 +97,7 @@ | ||
| 89 | 97 | public function __unserialize($data) |
| 90 | 98 | { |
| 91 | 99 | $this->token = $data['token']; |
| 92 | 100 | $this->expires = $data['expires']; |
| 101 | + $this->source = isset($data['source']) ? TokenSource::from($data['source']) : null; | |
| 93 | 102 | } |
| 94 | 103 | } |