0byt3m1n1
Path:
/
home
/
mgatv524
/
lot.mgaplay.com.br
/
lib
/
OAuth
/
[
Home
]
File: AccessTokenEntity.php
<?php /** * Copyright (C) 2021 Xibo Signage Ltd * * Xibo - Digital Signage - http://www.xibo.org.uk * * This file is part of Xibo. * * Xibo is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * Xibo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Xibo. If not, see <http://www.gnu.org/licenses/>. */ namespace Xibo\OAuth; use Carbon\Carbon; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Rsa\Sha256; use Lcobucci\JWT\Token; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; use League\OAuth2\Server\Entities\Traits\EntityTrait; use League\OAuth2\Server\Entities\Traits\TokenEntityTrait; /** * Class AccessTokenEntity * @package Xibo\OAuth */ class AccessTokenEntity implements AccessTokenEntityInterface { use AccessTokenTrait, TokenEntityTrait, EntityTrait; /** * Generate a JWT from the access token * * @param CryptKey $privateKey * * @return Token */ private function convertToJWT(CryptKey $privateKey) { $userId = $this->getUserIdentifier(); return (new Builder()) ->issuedBy('info@xibosignage.com') ->permittedFor($this->getClient()->getIdentifier()) ->identifiedBy($this->getIdentifier()) ->issuedAt(Carbon::now()->toDateTimeImmutable()) ->canOnlyBeUsedAfter(Carbon::now()->toDateTimeImmutable()) ->expiresAt($this->getExpiryDateTime()) ->relatedTo($userId) ->withClaim('scopes', $this->getScopes()) ->getToken(new Sha256(), new Key($privateKey->getKeyPath())) ; } /** * Generate a string representation from the access token */ public function __toString() { return (string) $this->convertToJWT($this->privateKey); } }