mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-01 16:33:07 +05:30
Added AccessTokenTrait
This commit is contained in:
parent
3c0a7f14ab
commit
be9bd76f35
32
src/Entities/Traits/AccessTokenTrait.php
Normal file
32
src/Entities/Traits/AccessTokenTrait.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user