mirror of
https://github.com/elyby/accounts.git
synced 2024-11-06 16:21:08 +05:30
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
namespace api\components\OAuth2\Entities;
|
|
|
|
use api\components\OAuth2\Storage\SessionStorage;
|
|
use ErrorException;
|
|
use League\OAuth2\Server\Entity\SessionEntity as OriginalSessionEntity;
|
|
|
|
class AccessTokenEntity extends \League\OAuth2\Server\Entity\AccessTokenEntity {
|
|
|
|
protected $sessionId;
|
|
|
|
public function getSessionId() {
|
|
return $this->sessionId;
|
|
}
|
|
|
|
public function setSessionId($sessionId) {
|
|
$this->sessionId = $sessionId;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
* @return static
|
|
*/
|
|
public function setSession(OriginalSessionEntity $session) {
|
|
parent::setSession($session);
|
|
$this->sessionId = $session->getId();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSession(): ?OriginalSessionEntity {
|
|
if ($this->session instanceof OriginalSessionEntity) {
|
|
return $this->session;
|
|
}
|
|
|
|
$sessionStorage = $this->server->getSessionStorage();
|
|
if (!$sessionStorage instanceof SessionStorage) {
|
|
throw new ErrorException('SessionStorage must be instance of ' . SessionStorage::class);
|
|
}
|
|
|
|
return $sessionStorage->getById($this->sessionId);
|
|
}
|
|
|
|
}
|