mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
33 lines
941 B
PHP
33 lines
941 B
PHP
<?php
|
|
|
|
namespace League\OAuth2\Server\Entities\Traits;
|
|
|
|
use Lcobucci\JWT\Builder;
|
|
use Lcobucci\JWT\Signer\Key;
|
|
use Lcobucci\JWT\Signer\Rsa\Sha256;
|
|
use League\OAuth2\Server\CryptKey;
|
|
|
|
trait AccessTokenTrait
|
|
{
|
|
/**
|
|
* Generate a JWT from the access token
|
|
*
|
|
* @param \League\OAuth2\Server\CryptKey $privateKey
|
|
*
|
|
* @return string
|
|
*/
|
|
public function convertToJWT(CryptKey $privateKey)
|
|
{
|
|
return (new Builder())
|
|
->setAudience($this->getClient()->getIdentifier())
|
|
->setId($this->getIdentifier(), true)
|
|
->setIssuedAt(time())
|
|
->setNotBefore(time())
|
|
->setExpiration($this->getExpiryDateTime()->getTimestamp())
|
|
->setSubject($this->getUserIdentifier())
|
|
->set('scopes', $this->getScopes())
|
|
->sign(new Sha256(), new Key($privateKey->getKeyPath(), $privateKey->getPassPhrase()))
|
|
->getToken();
|
|
}
|
|
}
|