| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Token; |
| 4 |
|
| 5 |
/** |
| 6 |
* Token that comes from the SSO provider |
| 7 |
*/ |
| 8 |
class SsoToken extends Token |
| 9 |
{ |
| 10 |
private $refreshToken; |
| 11 |
private $clientId; |
| 12 |
private $clientSecret; |
| 13 |
private $registrationExpiresAt; |
| 14 |
private $region; |
| 15 |
private $startUrl; |
| 16 |
/** |
| 17 |
* Constructs a new SSO token object, with the specified AWS |
| 18 |
* token |
| 19 |
* |
| 20 |
* @param string $token Security token to use |
| 21 |
* @param int $expires UNIX timestamp for when the token expires |
| 22 |
* @param int $refreshToken An opaque string returned by the sso-oidc service |
| 23 |
* @param int $clientId The client ID generated when performing the registration portion of the OIDC authorization flow |
| 24 |
* @param int $clientSecret The client secret generated when performing the registration portion of the OIDC authorization flow |
| 25 |
* @param int $registrationExpiresAt The expiration time of the client registration (clientId and clientSecret) |
| 26 |
* @param int $region The configured sso_region for the profile that credentials are being resolved for |
| 27 |
* @param int $startUrl The configured sso_start_url for the profile that credentials are being resolved for |
| 28 |
*/ |
| 29 |
public function __construct($token, $expires, $refreshToken = null, $clientId = null, $clientSecret = null, $registrationExpiresAt = null, $region = null, $startUrl = null) |
| 30 |
{ |
| 31 |
parent::__construct($token, $expires); |
| 32 |
$this->refreshToken = $refreshToken; |
| 33 |
$this->clientId = $clientId; |
| 34 |
$this->clientSecret = $clientSecret; |
| 35 |
$this->registrationExpiresAt = $registrationExpiresAt; |
| 36 |
$this->region = $region; |
| 37 |
$this->startUrl = $startUrl; |
| 38 |
} |
| 39 |
/** |
| 40 |
* @return bool |
| 41 |
*/ |
| 42 |
public function isExpired() |
| 43 |
{ |
| 44 |
if (isset($this->registrationExpiresAt) && \time() >= $this->registrationExpiresAt) { |
| 45 |
return \false; |
| 46 |
} |
| 47 |
return $this->expires !== null && \time() >= $this->expires; |
| 48 |
} |
| 49 |
/** |
| 50 |
* @return string|null |
| 51 |
*/ |
| 52 |
public function getRefreshToken() |
| 53 |
{ |
| 54 |
return $this->refreshToken; |
| 55 |
} |
| 56 |
/** |
| 57 |
* @return string|null |
| 58 |
*/ |
| 59 |
public function getClientId() |
| 60 |
{ |
| 61 |
return $this->clientId; |
| 62 |
} |
| 63 |
/** |
| 64 |
* @return string|null |
| 65 |
*/ |
| 66 |
public function getClientSecret() |
| 67 |
{ |
| 68 |
return $this->clientSecret; |
| 69 |
} |
| 70 |
/** |
| 71 |
* @return int|null |
| 72 |
*/ |
| 73 |
public function getRegistrationExpiresAt() |
| 74 |
{ |
| 75 |
return $this->registrationExpiresAt; |
| 76 |
} |
| 77 |
/** |
| 78 |
* @return string|null |
| 79 |
*/ |
| 80 |
public function getRegion() |
| 81 |
{ |
| 82 |
return $this->region; |
| 83 |
} |
| 84 |
/** |
| 85 |
* @return string|null |
| 86 |
*/ |
| 87 |
public function getStartUrl() |
| 88 |
{ |
| 89 |
return $this->startUrl; |
| 90 |
} |
| 91 |
/** |
| 92 |
* Creates an instance of SsoToken from a token data. |
| 93 |
* |
| 94 |
* @param $tokenData |
| 95 |
* |
| 96 |
* @return SsoToken |
| 97 |
*/ |
| 98 |
public static function fromTokenData($tokenData) : SsoToken |
| 99 |
{ |
| 100 |
return new SsoToken($tokenData['accessToken'], \strtotime($tokenData['expiresAt']), isset($tokenData['refreshToken']) ? $tokenData['refreshToken'] : null, isset($tokenData['clientId']) ? $tokenData['clientId'] : null, isset($tokenData['clientSecret']) ? $tokenData['clientSecret'] : null, isset($tokenData['registrationExpiresAt']) ? $tokenData['registrationExpiresAt'] : null, isset($tokenData['region']) ? $tokenData['region'] : null, isset($tokenData['startUrl']) ? $tokenData['startUrl'] : null); |
| 101 |
} |
| 102 |
} |
| 103 |
|