2016-11-29 04:27:58 +05:30
|
|
|
<?php
|
2019-08-02 21:02:08 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
namespace api\components\OAuth2\Entities;
|
|
|
|
|
2016-11-30 04:49:14 +05:30
|
|
|
use api\components\OAuth2\Storage\SessionStorage;
|
|
|
|
use League\OAuth2\Server\Entity\SessionEntity as OriginalSessionEntity;
|
2019-08-02 21:02:08 +05:30
|
|
|
use Webmozart\Assert\Assert;
|
2016-11-30 04:49:14 +05:30
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
class RefreshTokenEntity extends \League\OAuth2\Server\Entity\RefreshTokenEntity {
|
|
|
|
|
2016-11-30 04:49:14 +05:30
|
|
|
private $sessionId;
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function isExpired(): bool {
|
2016-11-29 04:27:58 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function getSession(): SessionEntity {
|
2016-11-30 04:49:14 +05:30
|
|
|
if ($this->session instanceof SessionEntity) {
|
|
|
|
return $this->session;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:02:08 +05:30
|
|
|
/** @var SessionStorage $sessionStorage */
|
2016-11-30 04:49:14 +05:30
|
|
|
$sessionStorage = $this->server->getSessionStorage();
|
2019-08-02 21:02:08 +05:30
|
|
|
Assert::isInstanceOf($sessionStorage, SessionStorage::class);
|
2016-11-30 04:49:14 +05:30
|
|
|
|
|
|
|
return $sessionStorage->getById($this->sessionId);
|
|
|
|
}
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function getSessionId(): int {
|
2016-11-30 04:49:14 +05:30
|
|
|
return $this->sessionId;
|
|
|
|
}
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function setSession(OriginalSessionEntity $session): self {
|
2016-11-30 04:49:14 +05:30
|
|
|
parent::setSession($session);
|
2019-08-02 21:02:08 +05:30
|
|
|
$this->setSessionId((int)$session->getId());
|
2016-11-30 04:49:14 +05:30
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function setSessionId(int $sessionId): void {
|
2016-11-30 04:49:14 +05:30
|
|
|
$this->sessionId = $sessionId;
|
|
|
|
}
|
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
}
|