123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace Aws\Token;
- class SsoToken extends Token
- {
- private $refreshToken;
- private $clientId;
- private $clientSecret;
- private $registrationExpiresAt;
- private $region;
- private $startUrl;
-
- public function __construct(
- $token,
- $expires,
- $refreshToken = null,
- $clientId = null,
- $clientSecret = null,
- $registrationExpiresAt = null,
- $region = null,
- $startUrl = null
- ) {
- parent::__construct($token, $expires);
- $this->refreshToken = $refreshToken;
- $this->clientId = $clientId;
- $this->clientSecret = $clientSecret;
- $this->registrationExpiresAt = $registrationExpiresAt;
- $this->region = $region;
- $this->startUrl = $startUrl;
- }
-
- public function isExpired()
- {
- if (isset($this->registrationExpiresAt)
- && time() >= $this->registrationExpiresAt
- ) {
- return false;
- }
- return $this->expires !== null && time() >= $this->expires;
- }
-
- public function getRefreshToken()
- {
- return $this->refreshToken;
- }
-
- public function getClientId()
- {
- return $this->clientId;
- }
-
- public function getClientSecret()
- {
- return $this->clientSecret;
- }
-
- public function getRegistrationExpiresAt()
- {
- return $this->registrationExpiresAt;
- }
-
- public function getRegion()
- {
- return $this->region;
- }
-
- public function getStartUrl()
- {
- return $this->startUrl;
- }
-
- public static function fromTokenData($tokenData): SsoToken
- {
- 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
- );
- }
- }
|