New entities, traits and interfaces

This commit is contained in:
Alex Bilbie 2015-04-05 14:03:25 +01:00
parent 171be1c422
commit a48630c837
15 changed files with 474 additions and 0 deletions

View 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;
}

View 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;
}

View 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;
}

View File

@ -0,0 +1,7 @@
<?php
namespace League\OAuth2\Server\Entities\Interfaces;
interface AccessTokenEntityInterface extends TokenInterface
{
}

View File

@ -0,0 +1,7 @@
<?php
namespace League\OAuth2\Server\Entities\Interfaces;
interface AuthCodeInterface extends TokenInterface
{
}

View 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);
}

View 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();
}

View 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);
}

View 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();
}

View 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;
}

View 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;
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}