mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
New entities, traits and interfaces
This commit is contained in:
parent
171be1c422
commit
a48630c837
11
src/Entities/AccessTokenEntity.php
Normal file
11
src/Entities/AccessTokenEntity.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||
|
||||
class AccessTokenEntity implements AccessTokenEntityInterface
|
||||
{
|
||||
use EntityTrait, TokenEntityTrait;
|
||||
}
|
15
src/Entities/AuthCodeEntity.php
Normal file
15
src/Entities/AuthCodeEntity.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AuthCodeInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||
|
||||
/**
|
||||
* Class AuthCodeEntity
|
||||
* @package League\OAuth2\Server
|
||||
*/
|
||||
class AuthCodeEntity implements AuthCodeInterface
|
||||
{
|
||||
use EntityTrait, TokenEntityTrait;
|
||||
}
|
15
src/Entities/ClientEntity.php
Normal file
15
src/Entities/ClientEntity.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\ClientEntityTrait;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
|
||||
/**
|
||||
* Class ClientEntity
|
||||
* @package League\OAuth2\Server
|
||||
*/
|
||||
class ClientEntity implements ClientEntityInterface
|
||||
{
|
||||
use EntityTrait, ClientEntityTrait;
|
||||
}
|
7
src/Entities/Interfaces/AccessTokenEntityInterface.php
Normal file
7
src/Entities/Interfaces/AccessTokenEntityInterface.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface AccessTokenEntityInterface extends TokenInterface
|
||||
{
|
||||
|
||||
}
|
7
src/Entities/Interfaces/AuthCodeEntityInterface.php
Normal file
7
src/Entities/Interfaces/AuthCodeEntityInterface.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface AuthCodeInterface extends TokenInterface
|
||||
{
|
||||
|
||||
}
|
42
src/Entities/Interfaces/ClientEntityInterface.php
Normal file
42
src/Entities/Interfaces/ClientEntityInterface.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface ClientEntityInterface
|
||||
{
|
||||
/**
|
||||
* Get the client's identifier
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the client's identifier
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Get the client's secret
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret();
|
||||
|
||||
/**
|
||||
* Set the client's secret
|
||||
* @param string $secret
|
||||
* @return string
|
||||
*/
|
||||
public function setSecret($secret);
|
||||
|
||||
/**
|
||||
* Get the client's name
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Set the client's name
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name);
|
||||
}
|
17
src/Entities/Interfaces/RefreshTokenEntityInterface.php
Normal file
17
src/Entities/Interfaces/RefreshTokenEntityInterface.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface RefreshTokenEntityInterface extends TokenInterface
|
||||
{
|
||||
/**
|
||||
* Set the original access token that the refresh token was associated with
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessToken
|
||||
*/
|
||||
public function setOriginalAccessToken(AccessTokenEntityInterface $accessToken);
|
||||
|
||||
/**
|
||||
* Get the access token that the refresh token was originally associated with
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface
|
||||
*/
|
||||
public function getOriginalAccessToken();
|
||||
}
|
17
src/Entities/Interfaces/ScopeEntityInterface.php
Normal file
17
src/Entities/Interfaces/ScopeEntityInterface.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface ScopeEntityInterface
|
||||
{
|
||||
/**
|
||||
* Get the scope's identifier
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the scope's identifier
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
}
|
79
src/Entities/Interfaces/TokenInterface.php
Normal file
79
src/Entities/Interfaces/TokenInterface.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface TokenInterface
|
||||
{
|
||||
/**
|
||||
* Get the token's identifier
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the token's identifier
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Get the token's expiry date time
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpiryDateTime();
|
||||
|
||||
/**
|
||||
* Set the date time when the token expires
|
||||
* @param \DateTime $dateTime
|
||||
*/
|
||||
public function setExpiryDateTime(\DateTime $dateTime);
|
||||
|
||||
/**
|
||||
* Set the token's owner
|
||||
* @param string $type The type of the owner (e.g. "user", "client" or something more specific)
|
||||
* @param string|int $identifier The identifier of the owner
|
||||
*/
|
||||
public function setOwner($type, $identifier);
|
||||
|
||||
/**
|
||||
* Get the token owner's type
|
||||
* @return string The type of owner (e.g. "user", "client" or something more specific)
|
||||
*/
|
||||
public function getOwnerType();
|
||||
|
||||
/**
|
||||
* Get the token owner's identifier
|
||||
* @return string|int
|
||||
*/
|
||||
public function getOwnerIdentifier();
|
||||
|
||||
/**
|
||||
* Get the client that the token was issued to
|
||||
* @return ClientEntityInterface
|
||||
*/
|
||||
public function getClient();
|
||||
|
||||
/**
|
||||
* Set the client that the token was issued to
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
|
||||
*/
|
||||
public function setClient(ClientEntityInterface $client);
|
||||
|
||||
/**
|
||||
* Associate a scope with the token
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface $scope
|
||||
*/
|
||||
public function addScope(ScopeEntityInterface $scope);
|
||||
|
||||
/**
|
||||
* Get an associated scope by the scope's identifier
|
||||
* @param string $identifier
|
||||
* @return ScopeEntityInterface|null The scope or null if not found
|
||||
*/
|
||||
public function getScopeWithIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Return an array of scopes associated with the token
|
||||
* @return ScopeEntityInterface[]
|
||||
*/
|
||||
public function getScopes();
|
||||
}
|
16
src/Entities/RefreshTokenEntity.php
Normal file
16
src/Entities/RefreshTokenEntity.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait;
|
||||
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||
|
||||
/**
|
||||
* Class RefreshTokenEntity
|
||||
* @package League\OAuth2\Server
|
||||
*/
|
||||
class RefreshTokenEntity implements RefreshTokenEntityInterface
|
||||
{
|
||||
use EntityTrait, TokenEntityTrait, RefreshTokenTrait;
|
||||
}
|
14
src/Entities/ScopeEntity.php
Normal file
14
src/Entities/ScopeEntity.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
|
||||
/**
|
||||
* Class ScopeEntity
|
||||
* @package League\OAuth2\Server
|
||||
*/
|
||||
class ScopeEntity implements ScopeEntityInterface
|
||||
{
|
||||
use EntityTrait;
|
||||
}
|
52
src/Entities/Traits/ClientEntityTrait.php
Normal file
52
src/Entities/Traits/ClientEntityTrait.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
trait ClientEntityTrait
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $secret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Get the client's secret
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret()
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the client's secret
|
||||
* @param string $secret
|
||||
* @return string
|
||||
*/
|
||||
public function setSecret($secret)
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client's name
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the client's name
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
26
src/Entities/Traits/EntityTrait.php
Normal file
26
src/Entities/Traits/EntityTrait.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
trait EntityTrait
|
||||
{
|
||||
/*
|
||||
* @var string
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIdentifier()
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
}
|
30
src/Entities/Traits/RefreshTokenTrait.php
Normal file
30
src/Entities/Traits/RefreshTokenTrait.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
|
||||
trait RefreshTokenTrait
|
||||
{
|
||||
/**
|
||||
* @var AccessTokenEntityInterface
|
||||
*/
|
||||
protected $originalAccessToken;
|
||||
|
||||
/**
|
||||
* Set the original access token that the refresh token was associated with
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessToken
|
||||
*/
|
||||
public function setOriginalAccessToken(AccessTokenEntityInterface $accessToken)
|
||||
{
|
||||
$this->originalAccessToken = $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the access token that the refresh token was originally associated with
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface
|
||||
*/
|
||||
public function getOriginalAccessToken()
|
||||
{
|
||||
return $this->originalAccessToken;
|
||||
}
|
||||
}
|
126
src/Entities/Traits/TokenEntityTrait.php
Normal file
126
src/Entities/Traits/TokenEntityTrait.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
||||
|
||||
trait TokenEntityTrait
|
||||
{
|
||||
/**
|
||||
* @var ScopeEntityInterface[]
|
||||
*/
|
||||
protected $scopes = [];
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $expiryDateTime;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $ownerType;
|
||||
|
||||
/**
|
||||
* @var string|int
|
||||
*/
|
||||
protected $ownerIdentifier;
|
||||
|
||||
/**
|
||||
* @var ClientEntityInterface
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Associate a scope with the token
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface $scope
|
||||
*/
|
||||
public function addScope(ScopeEntityInterface $scope)
|
||||
{
|
||||
$this->scopes[$scope->getIdentifier()] = $scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an associated scope by the scope's identifier
|
||||
* @param string $identifier
|
||||
* @return ScopeEntityInterface|null The scope or null if not found
|
||||
*/
|
||||
public function getScopeWithIdentifier($identifier)
|
||||
{
|
||||
return (isset($this->scopes[$identifier])) ? $this->scopes[$identifier] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of scopes associated with the token
|
||||
* @return ScopeEntityInterface[]
|
||||
*/
|
||||
public function getScopes()
|
||||
{
|
||||
return $this->scopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token's expiry date time
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpiryDateTime()
|
||||
{
|
||||
return $this->expiryDateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date time when the token expires
|
||||
* @param \DateTime $dateTime
|
||||
*/
|
||||
public function setExpiryDateTime(\DateTime $dateTime)
|
||||
{
|
||||
$this->expiryDateTime = $dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the token's owner
|
||||
* @param string $type The type of the owner (e.g. "user", "client" or something more specific)
|
||||
* @param string|int $identifier The identifier of the owner
|
||||
*/
|
||||
public function setOwner($type, $identifier)
|
||||
{
|
||||
$this->ownerType = $type;
|
||||
$this->ownerIdentifier = $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token owner's type
|
||||
* @return string The type of owner (e.g. "user", "client" or something more specific)
|
||||
*/
|
||||
public function getOwnerType()
|
||||
{
|
||||
return $this->ownerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token owner's identifier
|
||||
* @return string|int
|
||||
*/
|
||||
public function getOwnerIdentifier()
|
||||
{
|
||||
return $this->ownerIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
|
||||
*/
|
||||
public function setClient(ClientEntityInterface $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user