mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-15 09:47:46 +05:30
Access token can now return a JWT from itself
This commit is contained in:
parent
e08669d50c
commit
a1bdaae9a9
@ -2,6 +2,8 @@
|
||||
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Rsa\Sha256;
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||
@ -9,4 +11,25 @@ use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||
class AccessTokenEntity implements AccessTokenEntityInterface
|
||||
{
|
||||
use EntityTrait, TokenEntityTrait;
|
||||
|
||||
/**
|
||||
* Generate a JWT from the access token
|
||||
*
|
||||
* @param string $pathToPrivateKey
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convertToJWT($pathToPrivateKey)
|
||||
{
|
||||
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($pathToPrivateKey))
|
||||
->getToken();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,16 @@
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
use Lcobucci\JWT\Builder;
|
||||
|
||||
interface AccessTokenEntityInterface extends TokenInterface
|
||||
{
|
||||
/**
|
||||
* Generate a JWT from the access token
|
||||
*
|
||||
* @param string $pathToPrivateKey
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convertToJWT($pathToPrivateKey);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user