mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
118 lines
2.4 KiB
PHP
118 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
|
* @copyright Copyright (c) Alex Bilbie
|
|
* @license http://mit-license.org/
|
|
*
|
|
* @link https://github.com/thephpleague/oauth2-server
|
|
*/
|
|
|
|
namespace League\OAuth2\Server\Entities\Traits;
|
|
|
|
use DateTimeImmutable;
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface;
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface;
|
|
|
|
trait TokenEntityTrait
|
|
{
|
|
/**
|
|
* @var ScopeEntityInterface[]
|
|
*/
|
|
protected $scopes = [];
|
|
|
|
/**
|
|
* @var DateTimeImmutable
|
|
*/
|
|
protected $expiryDateTime;
|
|
|
|
/**
|
|
* @var string|int|null
|
|
*/
|
|
protected $userIdentifier;
|
|
|
|
/**
|
|
* @var ClientEntityInterface
|
|
*/
|
|
protected $client;
|
|
|
|
/**
|
|
* Associate a scope with the token.
|
|
*
|
|
* @param ScopeEntityInterface $scope
|
|
*/
|
|
public function addScope(ScopeEntityInterface $scope)
|
|
{
|
|
$this->scopes[$scope->getIdentifier()] = $scope;
|
|
}
|
|
|
|
/**
|
|
* Return an array of scopes associated with the token.
|
|
*
|
|
* @return ScopeEntityInterface[]
|
|
*/
|
|
public function getScopes()
|
|
{
|
|
return array_values($this->scopes);
|
|
}
|
|
|
|
/**
|
|
* Get the token's expiry date time.
|
|
*
|
|
* @return DateTimeImmutable
|
|
*/
|
|
public function getExpiryDateTime()
|
|
{
|
|
return $this->expiryDateTime;
|
|
}
|
|
|
|
/**
|
|
* Set the date time when the token expires.
|
|
*
|
|
* @param DateTimeImmutable $dateTime
|
|
*/
|
|
public function setExpiryDateTime(DateTimeImmutable $dateTime)
|
|
{
|
|
$this->expiryDateTime = $dateTime;
|
|
}
|
|
|
|
/**
|
|
* Set the identifier of the user associated with the token.
|
|
*
|
|
* @param string|int|null $identifier The identifier of the user
|
|
*/
|
|
public function setUserIdentifier($identifier)
|
|
{
|
|
$this->userIdentifier = $identifier;
|
|
}
|
|
|
|
/**
|
|
* Get the token user's identifier.
|
|
*
|
|
* @return string|int|null
|
|
*/
|
|
public function getUserIdentifier()
|
|
{
|
|
return $this->userIdentifier;
|
|
}
|
|
|
|
/**
|
|
* Get the client that the token was issued to.
|
|
*
|
|
* @return ClientEntityInterface
|
|
*/
|
|
public function getClient()
|
|
{
|
|
return $this->client;
|
|
}
|
|
|
|
/**
|
|
* Set the client that the token was issued to.
|
|
*
|
|
* @param ClientEntityInterface $client
|
|
*/
|
|
public function setClient(ClientEntityInterface $client)
|
|
{
|
|
$this->client = $client;
|
|
}
|
|
}
|