accessTokenModel = $accessTokenModel; $this->clientModel = $clientModel; } public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessTokenEntityInterface { $accessToken = new AccessToken(); $accessToken->setClient($clientEntity); $accessToken->setUserIdentifier($userIdentifier); foreach ($scopes as $scope) { $accessToken->addScope($scope); } return $accessToken; } public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): void { /** @var AccessToken $accessTokenEntity */ $accessToken = $this->accessTokenModel->getItemByIdentifier($accessTokenEntity->getIdentifier()); if ($accessToken->id > 0) { throw UniqueTokenIdentifierConstraintViolationException::create(); } /** @var AccessToken $accessTokenEntity */ $data = $accessTokenEntity->getData(); $client = $this->clientModel->getItemByIdentifier($accessTokenEntity->getClient()->getIdentifier()); $data['client_id'] = $client->id; unset($data['client_identifier']); $this->accessTokenModel->save($data); } public function revokeAccessToken($tokenId): void { $this->accessTokenModel->revoke($tokenId); } public function isAccessTokenRevoked($tokenId): bool { $accessToken = $this->accessTokenModel->getItemByIdentifier($tokenId); if (!$accessToken->id) { return true; } return !!$accessToken->revoked; } }