accounts/api/components/OAuth2/Entities/RefreshTokenEntity.php

46 lines
1.2 KiB
PHP
Raw Normal View History

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