This commit is contained in:
Graham Campbell 2014-12-10 13:10:35 +00:00
parent 8075190e0c
commit a1726903b5
45 changed files with 416 additions and 109 deletions

View File

@ -20,6 +20,6 @@ class Users
return $result; return $result;
} }
return null; return;
} }
} }

View File

@ -3,7 +3,6 @@
namespace RelationalExample\Storage; namespace RelationalExample\Storage;
use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Capsule\Manager as Capsule;
use League\OAuth2\Server\Entity\AbstractTokenEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Storage\AbstractStorage; use League\OAuth2\Server\Storage\AbstractStorage;
@ -28,7 +27,7 @@ class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
return $token; return $token;
} }
return null; return;
} }
/** /**

View File

@ -29,7 +29,7 @@ class AuthCodeStorage extends AbstractStorage implements AuthCodeInterface
return $token; return $token;
} }
return null; return;
} }
public function create($token, $expireTime, $sessionId, $redirectUri) public function create($token, $expireTime, $sessionId, $redirectUri)

View File

@ -41,7 +41,7 @@ class ClientStorage extends AbstractStorage implements ClientInterface
return $client; return $client;
} }
return null; return;
} }
/** /**
@ -65,6 +65,6 @@ class ClientStorage extends AbstractStorage implements ClientInterface
return $client; return $client;
} }
return null; return;
} }
} }

View File

@ -27,7 +27,7 @@ class RefreshTokenStorage extends AbstractStorage implements RefreshTokenInterfa
return $token; return $token;
} }
return null; return;
} }
/** /**

View File

@ -19,7 +19,7 @@ class ScopeStorage extends AbstractStorage implements ScopeInterface
->get(); ->get();
if (count($result) === 0) { if (count($result) === 0) {
return null; return;
} }
return (new ScopeEntity($this->server))->hydrate([ return (new ScopeEntity($this->server))->hydrate([

View File

@ -31,7 +31,7 @@ class SessionStorage extends AbstractStorage implements SessionInterface
return $session; return $session;
} }
return null; return;
} }
/** /**
@ -53,7 +53,7 @@ class SessionStorage extends AbstractStorage implements SessionInterface
return $session; return $session;
} }
return null; return;
} }
/** /**

View File

@ -36,48 +36,56 @@ abstract class AbstractServer
/** /**
* Session storage * Session storage
*
* @var \League\OAuth2\Server\Storage\SessionInterface * @var \League\OAuth2\Server\Storage\SessionInterface
*/ */
protected $sessionStorage; protected $sessionStorage;
/** /**
* Access token storage * Access token storage
*
* @var \League\OAuth2\Server\Storage\AccessTokenInterface * @var \League\OAuth2\Server\Storage\AccessTokenInterface
*/ */
protected $accessTokenStorage; protected $accessTokenStorage;
/** /**
* Refresh token storage * Refresh token storage
*
* @var \League\OAuth2\Server\Storage\RefreshTokenInterface * @var \League\OAuth2\Server\Storage\RefreshTokenInterface
*/ */
protected $refreshTokenStorage; protected $refreshTokenStorage;
/** /**
* Auth code storage * Auth code storage
*
* @var \League\OAuth2\Server\Storage\AuthCodeInterface * @var \League\OAuth2\Server\Storage\AuthCodeInterface
*/ */
protected $authCodeStorage; protected $authCodeStorage;
/** /**
* Scope storage * Scope storage
*
* @var \League\OAuth2\Server\Storage\ScopeInterface * @var \League\OAuth2\Server\Storage\ScopeInterface
*/ */
protected $scopeStorage; protected $scopeStorage;
/** /**
* Client storage * Client storage
*
* @var \League\OAuth2\Server\Storage\ClientInterface * @var \League\OAuth2\Server\Storage\ClientInterface
*/ */
protected $clientStorage; protected $clientStorage;
/** /**
* Token type * Token type
*
* @var \League\OAuth2\Server\TokenType\TokenTypeInterface * @var \League\OAuth2\Server\TokenType\TokenTypeInterface
*/ */
protected $tokenType; protected $tokenType;
/** /**
* Event emitter * Event emitter
*
* @var \League\Event\Emitter * @var \League\Event\Emitter
*/ */
protected $eventEmitter; protected $eventEmitter;
@ -92,6 +100,7 @@ abstract class AbstractServer
/** /**
* Set an event emitter * Set an event emitter
*
* @param object $emitter Event emitter object * @param object $emitter Event emitter object
*/ */
public function setEventEmitter($emitter = null) public function setEventEmitter($emitter = null)
@ -105,6 +114,7 @@ abstract class AbstractServer
/** /**
* Add an event listener to the event emitter * Add an event listener to the event emitter
*
* @param string $eventName Event name * @param string $eventName Event name
* @param callable $listener Callable function or method * @param callable $listener Callable function or method
*/ */
@ -115,6 +125,7 @@ abstract class AbstractServer
/** /**
* Returns the event emitter * Returns the event emitter
*
* @return \League\Event\Emitter * @return \League\Event\Emitter
*/ */
public function getEventEmitter() public function getEventEmitter()
@ -124,7 +135,9 @@ abstract class AbstractServer
/** /**
* Sets the Request Object * Sets the Request Object
*
* @param \Symfony\Component\HttpFoundation\Request The Request Object * @param \Symfony\Component\HttpFoundation\Request The Request Object
*
* @return self * @return self
*/ */
public function setRequest($request) public function setRequest($request)
@ -136,6 +149,7 @@ abstract class AbstractServer
/** /**
* Gets the Request object. It will create one from the globals if one is not set. * Gets the Request object. It will create one from the globals if one is not set.
*
* @return \Symfony\Component\HttpFoundation\Request * @return \Symfony\Component\HttpFoundation\Request
*/ */
public function getRequest() public function getRequest()
@ -149,7 +163,9 @@ abstract class AbstractServer
/** /**
* Set the client storage * Set the client storage
* @param \League\OAuth2\Server\Storage\ClientInterface $storage *
* @param \League\OAuth2\Server\Storage\ClientInterface $storage
*
* @return self * @return self
*/ */
public function setClientStorage(ClientInterface $storage) public function setClientStorage(ClientInterface $storage)
@ -162,7 +178,9 @@ abstract class AbstractServer
/** /**
* Set the session storage * Set the session storage
* @param \League\OAuth2\Server\Storage\SessionInterface $storage *
* @param \League\OAuth2\Server\Storage\SessionInterface $storage
*
* @return self * @return self
*/ */
public function setSessionStorage(SessionInterface $storage) public function setSessionStorage(SessionInterface $storage)
@ -175,7 +193,9 @@ abstract class AbstractServer
/** /**
* Set the access token storage * Set the access token storage
* @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage *
* @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage
*
* @return self * @return self
*/ */
public function setAccessTokenStorage(AccessTokenInterface $storage) public function setAccessTokenStorage(AccessTokenInterface $storage)
@ -188,7 +208,9 @@ abstract class AbstractServer
/** /**
* Set the refresh token storage * Set the refresh token storage
* @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage *
* @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage
*
* @return self * @return self
*/ */
public function setRefreshTokenStorage(RefreshTokenInterface $storage) public function setRefreshTokenStorage(RefreshTokenInterface $storage)
@ -201,7 +223,9 @@ abstract class AbstractServer
/** /**
* Set the auth code storage * Set the auth code storage
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage *
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage
*
* @return self * @return self
*/ */
public function setAuthCodeStorage(AuthCodeInterface $storage) public function setAuthCodeStorage(AuthCodeInterface $storage)
@ -214,7 +238,9 @@ abstract class AbstractServer
/** /**
* Set the scope storage * Set the scope storage
* @param \League\OAuth2\Server\Storage\ScopeInterface $storage *
* @param \League\OAuth2\Server\Storage\ScopeInterface $storage
*
* @return self * @return self
*/ */
public function setScopeStorage(ScopeInterface $storage) public function setScopeStorage(ScopeInterface $storage)
@ -227,6 +253,7 @@ abstract class AbstractServer
/** /**
* Return the client storage * Return the client storage
*
* @return \League\OAuth2\Server\Storage\ClientInterface * @return \League\OAuth2\Server\Storage\ClientInterface
*/ */
public function getClientStorage() public function getClientStorage()
@ -236,6 +263,7 @@ abstract class AbstractServer
/** /**
* Return the scope storage * Return the scope storage
*
* @return \League\OAuth2\Server\Storage\ScopeInterface * @return \League\OAuth2\Server\Storage\ScopeInterface
*/ */
public function getScopeStorage() public function getScopeStorage()
@ -245,6 +273,7 @@ abstract class AbstractServer
/** /**
* Return the session storage * Return the session storage
*
* @return \League\OAuth2\Server\Storage\SessionInterface * @return \League\OAuth2\Server\Storage\SessionInterface
*/ */
public function getSessionStorage() public function getSessionStorage()
@ -254,6 +283,7 @@ abstract class AbstractServer
/** /**
* Return the refresh token storage * Return the refresh token storage
*
* @return \League\OAuth2\Server\Storage\RefreshTokenInterface * @return \League\OAuth2\Server\Storage\RefreshTokenInterface
*/ */
public function getRefreshTokenStorage() public function getRefreshTokenStorage()
@ -263,6 +293,7 @@ abstract class AbstractServer
/** /**
* Return the access token storage * Return the access token storage
*
* @return \League\OAuth2\Server\Storage\AccessTokenInterface * @return \League\OAuth2\Server\Storage\AccessTokenInterface
*/ */
public function getAccessTokenStorage() public function getAccessTokenStorage()
@ -272,6 +303,7 @@ abstract class AbstractServer
/** /**
* Return the auth code storage * Return the auth code storage
*
* @return \League\OAuth2\Server\Storage\AuthCodeInterface * @return \League\OAuth2\Server\Storage\AuthCodeInterface
*/ */
public function getAuthCodeStorage() public function getAuthCodeStorage()
@ -281,7 +313,9 @@ abstract class AbstractServer
/** /**
* Set the access token type * Set the access token type
* @param TokenTypeInterface $tokenType The token type *
* @param TokenTypeInterface $tokenType The token type
*
* @return void * @return void
*/ */
public function setTokenType(TokenTypeInterface $tokenType) public function setTokenType(TokenTypeInterface $tokenType)
@ -292,6 +326,7 @@ abstract class AbstractServer
/** /**
* Get the access token type * Get the access token type
*
* @return TokenTypeInterface * @return TokenTypeInterface
*/ */
public function getTokenType() public function getTokenType()

View File

@ -22,48 +22,56 @@ class AuthorizationServer extends AbstractServer
/** /**
* The delimeter between scopes specified in the scope query string parameter * The delimeter between scopes specified in the scope query string parameter
* The OAuth 2 specification states it should be a space but most use a comma * The OAuth 2 specification states it should be a space but most use a comma
*
* @var string * @var string
*/ */
protected $scopeDelimiter = ' '; protected $scopeDelimiter = ' ';
/** /**
* The TTL (time to live) of an access token in seconds (default: 3600) * The TTL (time to live) of an access token in seconds (default: 3600)
*
* @var integer * @var integer
*/ */
protected $accessTokenTTL = 3600; protected $accessTokenTTL = 3600;
/** /**
* The registered grant response types * The registered grant response types
*
* @var array * @var array
*/ */
protected $responseTypes = []; protected $responseTypes = [];
/** /**
* The registered grant types * The registered grant types
*
* @var array * @var array
*/ */
protected $grantTypes = []; protected $grantTypes = [];
/** /**
* Require the "scope" parameter to be in checkAuthoriseParams() * Require the "scope" parameter to be in checkAuthoriseParams()
*
* @var boolean * @var boolean
*/ */
protected $requireScopeParam = false; protected $requireScopeParam = false;
/** /**
* Default scope(s) to be used if none is provided * Default scope(s) to be used if none is provided
*
* @var string|array * @var string|array
*/ */
protected $defaultScope; protected $defaultScope;
/** /**
* Require the "state" parameter to be in checkAuthoriseParams() * Require the "state" parameter to be in checkAuthoriseParams()
*
* @var boolean * @var boolean
*/ */
protected $requireStateParam = false; protected $requireStateParam = false;
/** /**
* Create a new OAuth2 authorization server * Create a new OAuth2 authorization server
*
* @return self * @return self
*/ */
public function __construct() public function __construct()
@ -78,8 +86,10 @@ class AuthorizationServer extends AbstractServer
/** /**
* Enable support for a grant * Enable support for a grant
* @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface *
* @param null|string $identifier An identifier for the grant (autodetected if not passed) * @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface
* @param null|string $identifier An identifier for the grant (autodetected if not passed)
*
* @return self * @return self
*/ */
public function addGrantType(GrantTypeInterface $grantType, $identifier = null) public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
@ -102,7 +112,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Check if a grant type has been enabled * Check if a grant type has been enabled
* @param string $identifier The grant type identifier *
* @param string $identifier The grant type identifier
*
* @return boolean Returns "true" if enabled, "false" if not * @return boolean Returns "true" if enabled, "false" if not
*/ */
public function hasGrantType($identifier) public function hasGrantType($identifier)
@ -112,6 +124,7 @@ class AuthorizationServer extends AbstractServer
/** /**
* Returns response types * Returns response types
*
* @return array * @return array
*/ */
public function getResponseTypes() public function getResponseTypes()
@ -121,7 +134,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Require the "scope" parameter in checkAuthoriseParams() * Require the "scope" parameter in checkAuthoriseParams()
* @param boolean $require *
* @param boolean $require
*
* @return self * @return self
*/ */
public function requireScopeParam($require = true) public function requireScopeParam($require = true)
@ -133,6 +148,7 @@ class AuthorizationServer extends AbstractServer
/** /**
* Is the scope parameter required? * Is the scope parameter required?
*
* @return bool * @return bool
*/ */
public function scopeParamRequired() public function scopeParamRequired()
@ -142,7 +158,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Default scope to be used if none is provided and requireScopeParam() is false * Default scope to be used if none is provided and requireScopeParam() is false
*
* @param string $default Name of the default scope * @param string $default Name of the default scope
*
* @return self * @return self
*/ */
public function setDefaultScope($default = null) public function setDefaultScope($default = null)
@ -154,6 +172,7 @@ class AuthorizationServer extends AbstractServer
/** /**
* Default scope to be used if none is provided and requireScopeParam is false * Default scope to be used if none is provided and requireScopeParam is false
*
* @return string|null * @return string|null
*/ */
public function getDefaultScope() public function getDefaultScope()
@ -163,6 +182,7 @@ class AuthorizationServer extends AbstractServer
/** /**
* Require the "state" paremter in checkAuthoriseParams() * Require the "state" paremter in checkAuthoriseParams()
*
* @return bool * @return bool
*/ */
public function stateParamRequired() public function stateParamRequired()
@ -172,7 +192,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Require the "state" paremter in checkAuthoriseParams() * Require the "state" paremter in checkAuthoriseParams()
* @param boolean $require *
* @param boolean $require
*
* @return self * @return self
*/ */
public function requireStateParam($require = true) public function requireStateParam($require = true)
@ -184,6 +206,7 @@ class AuthorizationServer extends AbstractServer
/** /**
* Get the scope delimiter * Get the scope delimiter
*
* @return string The scope delimiter (default: ",") * @return string The scope delimiter (default: ",")
*/ */
public function getScopeDelimiter() public function getScopeDelimiter()
@ -193,7 +216,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Set the scope delimiter * Set the scope delimiter
*
* @param string $scopeDelimiter * @param string $scopeDelimiter
*
* @return self * @return self
*/ */
public function setScopeDelimiter($scopeDelimiter = ' ') public function setScopeDelimiter($scopeDelimiter = ' ')
@ -205,6 +230,7 @@ class AuthorizationServer extends AbstractServer
/** /**
* Get the TTL for an access token * Get the TTL for an access token
*
* @return int The TTL * @return int The TTL
*/ */
public function getAccessTokenTTL() public function getAccessTokenTTL()
@ -214,7 +240,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Set the TTL for an access token * Set the TTL for an access token
*
* @param int $accessTokenTTL The new TTL * @param int $accessTokenTTL The new TTL
*
* @return self * @return self
*/ */
public function setAccessTokenTTL($accessTokenTTL = 3600) public function setAccessTokenTTL($accessTokenTTL = 3600)
@ -226,7 +254,9 @@ class AuthorizationServer extends AbstractServer
/** /**
* Issue an access token * Issue an access token
*
* @return array Authorise request parameters * @return array Authorise request parameters
*
* @throws * @throws
*/ */
public function issueAccessToken() public function issueAccessToken()
@ -247,8 +277,11 @@ class AuthorizationServer extends AbstractServer
/** /**
* Return a grant type class * Return a grant type class
* @param string $grantType The grant type identifier *
* @param string $grantType The grant type identifier
*
* @return Grant\GrantTypeInterface * @return Grant\GrantTypeInterface
*
* @throws * @throws
*/ */
public function getGrantType($grantType) public function getGrantType($grantType)

View File

@ -21,37 +21,44 @@ abstract class AbstractTokenEntity
{ {
/** /**
* Token identifier * Token identifier
*
* @var string * @var string
*/ */
protected $id; protected $id;
/** /**
* Associated session * Associated session
*
* @var \League\OAuth2\Server\Entity\SessionEntity * @var \League\OAuth2\Server\Entity\SessionEntity
*/ */
protected $session; protected $session;
/** /**
* Session scopes * Session scopes
*
* @var \League\OAuth2\Server\Entity\ScopeEntity[] * @var \League\OAuth2\Server\Entity\ScopeEntity[]
*/ */
protected $scopes; protected $scopes;
/** /**
* Token expire time * Token expire time
*
* @var int * @var int
*/ */
protected $expireTime = 0; protected $expireTime = 0;
/** /**
* Authorization or resource server * Authorization or resource server
*
* @var \League\OAuth2\Server\AbstractServer * @var \League\OAuth2\Server\AbstractServer
*/ */
protected $server; protected $server;
/** /**
* __construct * __construct
* @param \League\OAuth2\Server\AbstractServer $server *
* @param \League\OAuth2\Server\AbstractServer $server
*
* @return self * @return self
*/ */
public function __construct(AbstractServer $server) public function __construct(AbstractServer $server)
@ -63,7 +70,9 @@ abstract class AbstractTokenEntity
/** /**
* Set session * Set session
* @param \League\OAuth2\Server\Entity\SessionEntity $session *
* @param \League\OAuth2\Server\Entity\SessionEntity $session
*
* @return self * @return self
*/ */
public function setSession(SessionEntity $session) public function setSession(SessionEntity $session)
@ -75,7 +84,9 @@ abstract class AbstractTokenEntity
/** /**
* Set the expire time of the token * Set the expire time of the token
* @param integer $expireTime Unix time stamp *
* @param integer $expireTime Unix time stamp
*
* @return self * @return self
*/ */
public function setExpireTime($expireTime) public function setExpireTime($expireTime)
@ -87,6 +98,7 @@ abstract class AbstractTokenEntity
/** /**
* Return token expire time * Return token expire time
*
* @return int * @return int
*/ */
public function getExpireTime() public function getExpireTime()
@ -96,6 +108,7 @@ abstract class AbstractTokenEntity
/** /**
* Is the token expired? * Is the token expired?
*
* @return bool * @return bool
*/ */
public function isExpired() public function isExpired()
@ -105,7 +118,9 @@ abstract class AbstractTokenEntity
/** /**
* Set token ID * Set token ID
* @param string $id Token ID *
* @param string $id Token ID
*
* @return self * @return self
*/ */
public function setId($id = null) public function setId($id = null)
@ -117,6 +132,7 @@ abstract class AbstractTokenEntity
/** /**
* Get the token ID * Get the token ID
*
* @return string * @return string
*/ */
public function getId() public function getId()
@ -126,7 +142,9 @@ abstract class AbstractTokenEntity
/** /**
* Associate a scope * Associate a scope
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope *
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope
*
* @return self * @return self
*/ */
public function associateScope(ScopeEntity $scope) public function associateScope(ScopeEntity $scope)
@ -140,7 +158,9 @@ abstract class AbstractTokenEntity
/** /**
* Format the local scopes array * Format the local scopes array
*
* @param \League\OAuth2\Server\Entity\ScopeEntity[] * @param \League\OAuth2\Server\Entity\ScopeEntity[]
*
* @return array * @return array
*/ */
protected function formatScopes($unformatted = []) protected function formatScopes($unformatted = [])
@ -161,6 +181,7 @@ abstract class AbstractTokenEntity
/** /**
* Returns the token as a string if the object is cast as a string * Returns the token as a string if the object is cast as a string
*
* @return string * @return string
*/ */
public function __toString() public function __toString()
@ -174,12 +195,14 @@ abstract class AbstractTokenEntity
/** /**
* Expire the token * Expire the token
*
* @return void * @return void
*/ */
abstract public function expire(); abstract public function expire();
/** /**
* Save the token * Save the token
*
* @return void * @return void
*/ */
abstract public function save(); abstract public function save();

View File

@ -18,6 +18,7 @@ class AccessTokenEntity extends AbstractTokenEntity
{ {
/** /**
* Get session * Get session
*
* @return \League\OAuth2\Server\Entity\SessionEntity * @return \League\OAuth2\Server\Entity\SessionEntity
*/ */
public function getSession() public function getSession()
@ -33,7 +34,9 @@ class AccessTokenEntity extends AbstractTokenEntity
/** /**
* Check if access token has an associated scope * Check if access token has an associated scope
* @param string $scope Scope to check *
* @param string $scope Scope to check
*
* @return bool * @return bool
*/ */
public function hasScope($scope) public function hasScope($scope)
@ -47,6 +50,7 @@ class AccessTokenEntity extends AbstractTokenEntity
/** /**
* Return all scopes associated with the access token * Return all scopes associated with the access token
*
* @return \League\OAuth2\Server\Entity\ScopeEntity[] * @return \League\OAuth2\Server\Entity\ScopeEntity[]
*/ */
public function getScopes() public function getScopes()

View File

@ -18,13 +18,16 @@ class AuthCodeEntity extends AbstractTokenEntity
{ {
/** /**
* Redirect URI * Redirect URI
*
* @var string * @var string
*/ */
protected $redirectUri = ''; protected $redirectUri = '';
/** /**
* Set the redirect URI for the authorization request * Set the redirect URI for the authorization request
* @param string $redirectUri *
* @param string $redirectUri
*
* @return self * @return self
*/ */
public function setRedirectUri($redirectUri) public function setRedirectUri($redirectUri)
@ -36,6 +39,7 @@ class AuthCodeEntity extends AbstractTokenEntity
/** /**
* Get the redirect URI * Get the redirect URI
*
* @return string * @return string
*/ */
public function getRedirectUri() public function getRedirectUri()
@ -45,8 +49,10 @@ class AuthCodeEntity extends AbstractTokenEntity
/** /**
* Generate a redirect URI * Generate a redirect URI
* @param string $state The state parameter if set by the client *
* @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant) * @param string $state The state parameter if set by the client
* @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant)
*
* @return string * @return string
*/ */
public function generateRedirectUri($state = null, $queryDelimeter = '?') public function generateRedirectUri($state = null, $queryDelimeter = '?')
@ -62,6 +68,7 @@ class AuthCodeEntity extends AbstractTokenEntity
/** /**
* Get session * Get session
*
* @return \League\OAuth2\Server\Entity\SessionEntity * @return \League\OAuth2\Server\Entity\SessionEntity
*/ */
public function getSession() public function getSession()
@ -77,6 +84,7 @@ class AuthCodeEntity extends AbstractTokenEntity
/** /**
* Return all scopes associated with the session * Return all scopes associated with the session
*
* @return \League\OAuth2\Server\Entity\ScopeEntity[] * @return \League\OAuth2\Server\Entity\ScopeEntity[]
*/ */
public function getScopes() public function getScopes()

View File

@ -22,37 +22,44 @@ class ClientEntity
/** /**
* Client identifier * Client identifier
*
* @var string * @var string
*/ */
protected $id = null; protected $id = null;
/** /**
* Client secret * Client secret
*
* @var string * @var string
*/ */
protected $secret = null; protected $secret = null;
/** /**
* Client name * Client name
*
* @var string * @var string
*/ */
protected $name = null; protected $name = null;
/** /**
* Client redirect URI * Client redirect URI
*
* @var string * @var string
*/ */
protected $redirectUri = null; protected $redirectUri = null;
/** /**
* Authorization or resource server * Authorization or resource server
*
* @var \League\OAuth2\Server\AbstractServer * @var \League\OAuth2\Server\AbstractServer
*/ */
protected $server; protected $server;
/** /**
* __construct * __construct
* @param \League\OAuth2\Server\AbstractServer $server *
* @param \League\OAuth2\Server\AbstractServer $server
*
* @return self * @return self
*/ */
public function __construct(AbstractServer $server) public function __construct(AbstractServer $server)
@ -64,6 +71,7 @@ class ClientEntity
/** /**
* Return the client identifier * Return the client identifier
*
* @return string * @return string
*/ */
public function getId() public function getId()
@ -73,6 +81,7 @@ class ClientEntity
/** /**
* Return the client secret * Return the client secret
*
* @return string * @return string
*/ */
public function getSecret() public function getSecret()
@ -82,6 +91,7 @@ class ClientEntity
/** /**
* Get the client name * Get the client name
*
* @return string * @return string
*/ */
public function getName() public function getName()
@ -91,6 +101,7 @@ class ClientEntity
/** /**
* Returnt the client redirect URI * Returnt the client redirect URI
*
* @return string * @return string
*/ */
public function getRedirectUri() public function getRedirectUri()

View File

@ -15,7 +15,9 @@ trait EntityTrait
{ {
/** /**
* Hydrate an entity with properites * Hydrate an entity with properites
*
* @param array $properties * @param array $properties
*
* @return self * @return self
*/ */
public function hydrate(array $properties) public function hydrate(array $properties)

View File

@ -18,19 +18,23 @@ class RefreshTokenEntity extends AbstractTokenEntity
{ {
/** /**
* Access token associated to refresh token * Access token associated to refresh token
*
* @var \League\OAuth2\Server\Entity\AccessTokenEntity * @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
protected $accessTokenEntity; protected $accessTokenEntity;
/** /**
* Id of the access token * Id of the access token
*
* @var string * @var string
*/ */
protected $accessTokenId; protected $accessTokenId;
/** /**
* Set the ID of the associated access token * Set the ID of the associated access token
* @param string $accessTokenId *
* @param string $accessTokenId
*
* @return self * @return self
*/ */
public function setAccessTokenId($accessTokenId) public function setAccessTokenId($accessTokenId)
@ -42,7 +46,9 @@ class RefreshTokenEntity extends AbstractTokenEntity
/** /**
* Associate an access token * Associate an access token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessTokenEntity *
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessTokenEntity
*
* @return self * @return self
*/ */
public function setAccessToken(AccessTokenEntity $accessTokenEntity) public function setAccessToken(AccessTokenEntity $accessTokenEntity)
@ -54,6 +60,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
/** /**
* Return access token * Return access token
*
* @return AccessTokenEntity * @return AccessTokenEntity
*/ */
public function getAccessToken() public function getAccessToken()

View File

@ -22,25 +22,30 @@ class ScopeEntity implements \JsonSerializable
/** /**
* Scope identifier * Scope identifier
*
* @var string * @var string
*/ */
protected $id; protected $id;
/** /**
* Scope description * Scope description
*
* @var string * @var string
*/ */
protected $description; protected $description;
/** /**
* Authorization or resource server * Authorization or resource server
*
* @var \League\OAuth2\Server\AbstractServer * @var \League\OAuth2\Server\AbstractServer
*/ */
protected $server; protected $server;
/** /**
* __construct * __construct
* @param \League\OAuth2\Server\AbstractServer $server *
* @param \League\OAuth2\Server\AbstractServer $server
*
* @return self * @return self
*/ */
public function __construct(AbstractServer $server) public function __construct(AbstractServer $server)
@ -52,6 +57,7 @@ class ScopeEntity implements \JsonSerializable
/** /**
* Return the scope identifer * Return the scope identifer
*
* @return string * @return string
*/ */
public function getId() public function getId()
@ -61,6 +67,7 @@ class ScopeEntity implements \JsonSerializable
/** /**
* Return the scope's description * Return the scope's description
*
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
@ -70,6 +77,7 @@ class ScopeEntity implements \JsonSerializable
/** /**
* Returns a JSON object when entity is passed into json_encode * Returns a JSON object when entity is passed into json_encode
*
* @return array * @return array
*/ */
public function jsonSerialize() public function jsonSerialize()

View File

@ -21,61 +21,72 @@ class SessionEntity
{ {
/** /**
* Session identifier * Session identifier
*
* @var string * @var string
*/ */
protected $id; protected $id;
/** /**
* Client identifier * Client identifier
*
* @var \League\OAuth2\Server\Entity\ClientEntity * @var \League\OAuth2\Server\Entity\ClientEntity
*/ */
protected $client; protected $client;
/** /**
* Session owner identifier * Session owner identifier
*
* @var string * @var string
*/ */
protected $ownerId; protected $ownerId;
/** /**
* Session owner type (e.g. "user") * Session owner type (e.g. "user")
*
* @var string * @var string
*/ */
protected $ownerType; protected $ownerType;
/** /**
* Auth code * Auth code
*
* @var \League\OAuth2\Server\Entity\AuthCodeEntity * @var \League\OAuth2\Server\Entity\AuthCodeEntity
*/ */
protected $authCode; protected $authCode;
/** /**
* Access token * Access token
*
* @var \League\OAuth2\Server\Entity\AccessTokenEntity * @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
protected $accessToken; protected $accessToken;
/** /**
* Refresh token * Refresh token
*
* @var \League\OAuth2\Server\Entity\RefreshTokenEntity * @var \League\OAuth2\Server\Entity\RefreshTokenEntity
*/ */
protected $refreshToken; protected $refreshToken;
/** /**
* Session scopes * Session scopes
*
* @var \Symfony\Component\HttpFoundation\ParameterBag * @var \Symfony\Component\HttpFoundation\ParameterBag
*/ */
protected $scopes; protected $scopes;
/** /**
* Authorization or resource server * Authorization or resource server
*
* @var \League\OAuth2\Server\AuthorizationServer|\League\OAuth2\Server\ResourceServer * @var \League\OAuth2\Server\AuthorizationServer|\League\OAuth2\Server\ResourceServer
*/ */
protected $server; protected $server;
/** /**
* __construct * __construct
* @param \League\OAuth2\Server\AbstractServer $server *
* @param \League\OAuth2\Server\AbstractServer $server
*
* @return self * @return self
*/ */
public function __construct(AbstractServer $server) public function __construct(AbstractServer $server)
@ -87,7 +98,9 @@ class SessionEntity
/** /**
* Set the session identifier * Set the session identifier
* @param string $id *
* @param string $id
*
* @return self * @return self
*/ */
public function setId($id) public function setId($id)
@ -99,6 +112,7 @@ class SessionEntity
/** /**
* Return the session identifier * Return the session identifier
*
* @return string * @return string
*/ */
public function getId() public function getId()
@ -108,7 +122,9 @@ class SessionEntity
/** /**
* Associate a scope * Associate a scope
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope *
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope
*
* @return self * @return self
*/ */
public function associateScope(ScopeEntity $scope) public function associateScope(ScopeEntity $scope)
@ -122,7 +138,9 @@ class SessionEntity
/** /**
* Check if access token has an associated scope * Check if access token has an associated scope
* @param string $scope Scope to check *
* @param string $scope Scope to check
*
* @return bool * @return bool
*/ */
public function hasScope($scope) public function hasScope($scope)
@ -136,6 +154,7 @@ class SessionEntity
/** /**
* Return all scopes associated with the session * Return all scopes associated with the session
*
* @return \League\OAuth2\Server\Entity\ScopeEntity[] * @return \League\OAuth2\Server\Entity\ScopeEntity[]
*/ */
public function getScopes() public function getScopes()
@ -149,7 +168,9 @@ class SessionEntity
/** /**
* Format the local scopes array * Format the local scopes array
*
* @param \League\OAuth2\Server\Entity\Scope[] * @param \League\OAuth2\Server\Entity\Scope[]
*
* @return array * @return array
*/ */
private function formatScopes($unformatted = []) private function formatScopes($unformatted = [])
@ -168,7 +189,9 @@ class SessionEntity
/** /**
* Associate an access token with the session * Associate an access token with the session
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken *
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
*
* @return self * @return self
*/ */
public function associateAccessToken(AccessTokenEntity $accessToken) public function associateAccessToken(AccessTokenEntity $accessToken)
@ -180,7 +203,9 @@ class SessionEntity
/** /**
* Associate a refresh token with the session * Associate a refresh token with the session
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $refreshToken *
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $refreshToken
*
* @return self * @return self
*/ */
public function associateRefreshToken(RefreshTokenEntity $refreshToken) public function associateRefreshToken(RefreshTokenEntity $refreshToken)
@ -192,7 +217,9 @@ class SessionEntity
/** /**
* Associate a client with the session * Associate a client with the session
* @param \League\OAuth2\Server\Entity\ClientEntity $client The client *
* @param \League\OAuth2\Server\Entity\ClientEntity $client The client
*
* @return self * @return self
*/ */
public function associateClient(ClientEntity $client) public function associateClient(ClientEntity $client)
@ -204,6 +231,7 @@ class SessionEntity
/** /**
* Return the session client * Return the session client
*
* @return \League\OAuth2\Server\Entity\ClientEntity * @return \League\OAuth2\Server\Entity\ClientEntity
*/ */
public function getClient() public function getClient()
@ -219,8 +247,10 @@ class SessionEntity
/** /**
* Set the session owner * Set the session owner
* @param string $type The type of the owner (e.g. user, app) *
* @param string $id The identifier of the owner * @param string $type The type of the owner (e.g. user, app)
* @param string $id The identifier of the owner
*
* @return self * @return self
*/ */
public function setOwner($type, $id) public function setOwner($type, $id)
@ -235,6 +265,7 @@ class SessionEntity
/** /**
* Return session owner identifier * Return session owner identifier
*
* @return string * @return string
*/ */
public function getOwnerId() public function getOwnerId()
@ -244,6 +275,7 @@ class SessionEntity
/** /**
* Return session owner type * Return session owner type
*
* @return string * @return string
*/ */
public function getOwnerType() public function getOwnerType()
@ -253,6 +285,7 @@ class SessionEntity
/** /**
* Save the session * Save the session
*
* @return void * @return void
*/ */
public function save() public function save()

View File

@ -18,12 +18,14 @@ class ClientAuthenticationFailedEvent extends AbstractEvent
{ {
/** /**
* Request * Request
*
* @var \Symfony\Component\HttpFoundation\Request * @var \Symfony\Component\HttpFoundation\Request
*/ */
private $request; private $request;
/** /**
* Init the event with a request * Init the event with a request
*
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\Request $request
*/ */
public function __construct(Request $request) public function __construct(Request $request)
@ -33,6 +35,7 @@ class ClientAuthenticationFailedEvent extends AbstractEvent
/** /**
* The name of the event * The name of the event
*
* @return string * @return string
*/ */
public function getName() public function getName()
@ -42,6 +45,7 @@ class ClientAuthenticationFailedEvent extends AbstractEvent
/** /**
* Return request * Return request
*
* @return \Symfony\Component\HttpFoundation\Request * @return \Symfony\Component\HttpFoundation\Request
*/ */
public function getRequest() public function getRequest()

View File

@ -18,12 +18,14 @@ class SessionOwnerEvent extends AbstractEvent
{ {
/** /**
* Session entity * Session entity
*
* @var \League\OAuth2\Server\Entity\SessionEntity * @var \League\OAuth2\Server\Entity\SessionEntity
*/ */
private $session; private $session;
/** /**
* Init the event with a session * Init the event with a session
*
* @param \League\OAuth2\Server\Entity\SessionEntity $session * @param \League\OAuth2\Server\Entity\SessionEntity $session
*/ */
public function __construct(SessionEntity $session) public function __construct(SessionEntity $session)
@ -33,6 +35,7 @@ class SessionOwnerEvent extends AbstractEvent
/** /**
* The name of the event * The name of the event
*
* @return string * @return string
*/ */
public function getName() public function getName()
@ -42,6 +45,7 @@ class SessionOwnerEvent extends AbstractEvent
/** /**
* Return session * Return session
*
* @return \League\OAuth2\Server\Entity\SessionEntity * @return \League\OAuth2\Server\Entity\SessionEntity
*/ */
public function getSession() public function getSession()

View File

@ -18,12 +18,14 @@ class UserAuthenticationFailedEvent extends AbstractEvent
{ {
/** /**
* Request * Request
*
* @var \Symfony\Component\HttpFoundation\Request * @var \Symfony\Component\HttpFoundation\Request
*/ */
private $request; private $request;
/** /**
* Init the event with a request * Init the event with a request
*
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\Request $request
*/ */
public function __construct(Request $request) public function __construct(Request $request)
@ -33,6 +35,7 @@ class UserAuthenticationFailedEvent extends AbstractEvent
/** /**
* The name of the event * The name of the event
*
* @return string * @return string
*/ */
public function getName() public function getName()
@ -42,6 +45,7 @@ class UserAuthenticationFailedEvent extends AbstractEvent
/** /**
* Return request * Return request
*
* @return \Symfony\Component\HttpFoundation\Request * @return \Symfony\Component\HttpFoundation\Request
*/ */
public function getRequest() public function getRequest()

View File

@ -26,6 +26,7 @@ class OAuthException extends \Exception
/** /**
* Redirect URI if the server should redirect back to the client * Redirect URI if the server should redirect back to the client
*
* @var string|null * @var string|null
*/ */
public $redirectUri = null; public $redirectUri = null;
@ -37,6 +38,7 @@ class OAuthException extends \Exception
/** /**
* Throw a new exception * Throw a new exception
*
* @param string $msg Exception Message * @param string $msg Exception Message
*/ */
public function __construct($msg = 'An error occured') public function __construct($msg = 'An error occured')
@ -46,6 +48,7 @@ class OAuthException extends \Exception
/** /**
* Should the server redirect back to the client? * Should the server redirect back to the client?
*
* @return bool * @return bool
*/ */
public function shouldRedirect() public function shouldRedirect()
@ -55,6 +58,7 @@ class OAuthException extends \Exception
/** /**
* Return redirect URI if set * Return redirect URI if set
*
* @return string|null * @return string|null
*/ */
public function getRedirectUri() public function getRedirectUri()
@ -70,6 +74,7 @@ class OAuthException extends \Exception
/** /**
* Get all headers that have to be send with the error response * Get all headers that have to be send with the error response
*
* @return array Array with header values * @return array Array with header values
*/ */
public function getHttpHeaders() public function getHttpHeaders()

View File

@ -23,30 +23,35 @@ abstract class AbstractGrant implements GrantTypeInterface
{ {
/** /**
* Grant identifier * Grant identifier
*
* @var string * @var string
*/ */
protected $identifier = ''; protected $identifier = '';
/** /**
* Response type * Response type
*
* @var string * @var string
*/ */
protected $responseType; protected $responseType;
/** /**
* Callback to authenticate a user's name and password * Callback to authenticate a user's name and password
*
* @var callable * @var callable
*/ */
protected $callback; protected $callback;
/** /**
* AuthServer instance * AuthServer instance
*
* @var \League\OAuth2\Server\AuthorizationServer * @var \League\OAuth2\Server\AuthorizationServer
*/ */
protected $server; protected $server;
/** /**
* Access token expires in override * Access token expires in override
*
* @var int * @var int
*/ */
protected $accessTokenTTL; protected $accessTokenTTL;
@ -79,6 +84,7 @@ abstract class AbstractGrant implements GrantTypeInterface
/** /**
* Get the TTL for an access token * Get the TTL for an access token
*
* @return int The TTL * @return int The TTL
*/ */
public function getAccessTokenTTL() public function getAccessTokenTTL()
@ -92,7 +98,9 @@ abstract class AbstractGrant implements GrantTypeInterface
/** /**
* Override the default access token expire time * Override the default access token expire time
* @param int $accessTokenTTL *
* @param int $accessTokenTTL
*
* @return self * @return self
*/ */
public function setAccessTokenTTL($accessTokenTTL) public function setAccessTokenTTL($accessTokenTTL)
@ -114,10 +122,13 @@ abstract class AbstractGrant implements GrantTypeInterface
/** /**
* Given a list of scopes, validate them and return an array of Scope entities * Given a list of scopes, validate them and return an array of Scope entities
* @param string $scopeParam A string of scopes (e.g. "profile email birthday") *
* @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity * @param string $scopeParam A string of scopes (e.g. "profile email birthday")
* @param string|null $redirectUri The redirect URI to return the user to * @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity
* @param string|null $redirectUri The redirect URI to return the user to
*
* @return \League\OAuth2\Server\Entity\ScopeEntity[] * @return \League\OAuth2\Server\Entity\ScopeEntity[]
*
* @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required * @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required
* @throws * @throws
*/ */
@ -167,7 +178,9 @@ abstract class AbstractGrant implements GrantTypeInterface
/** /**
* Format the local scopes array * Format the local scopes array
*
* @param \League\OAuth2\Server\Entity\ScopeEntity[] * @param \League\OAuth2\Server\Entity\ScopeEntity[]
*
* @return array * @return array
*/ */
protected function formatScopes($unformated = []) protected function formatScopes($unformated = [])

View File

@ -27,37 +27,44 @@ class AuthCodeGrant extends AbstractGrant
{ {
/** /**
* Grant identifier * Grant identifier
*
* @var string * @var string
*/ */
protected $identifier = 'authorization_code'; protected $identifier = 'authorization_code';
/** /**
* Response type * Response type
*
* @var string * @var string
*/ */
protected $responseType = 'code'; protected $responseType = 'code';
/** /**
* AuthServer instance * AuthServer instance
*
* @var \League\OAuth2\Server\AuthorizationServer * @var \League\OAuth2\Server\AuthorizationServer
*/ */
protected $server = null; protected $server = null;
/** /**
* Access token expires in override * Access token expires in override
*
* @var int * @var int
*/ */
protected $accessTokenTTL = null; protected $accessTokenTTL = null;
/** /**
* The TTL of the auth token * The TTL of the auth token
*
* @var integer * @var integer
*/ */
protected $authTokenTTL = 600; protected $authTokenTTL = 600;
/** /**
* Override the default access token expire time * Override the default access token expire time
* @param int $authTokenTTL *
* @param int $authTokenTTL
*
* @return void * @return void
*/ */
public function setAuthTokenTTL($authTokenTTL) public function setAuthTokenTTL($authTokenTTL)
@ -129,9 +136,10 @@ class AuthCodeGrant extends AbstractGrant
/** /**
* Parse a new authorize request * Parse a new authorize request
* *
* @param string $type The session owner's type * @param string $type The session owner's type
* @param string $typeId The session owner's ID * @param string $typeId The session owner's ID
* @param array $authParams The authorize request $_GET parameters * @param array $authParams The authorize request $_GET parameters
*
* @return string An authorisation code * @return string An authorisation code
*/ */
public function newAuthorizeRequest($type, $typeId, $authParams = []) public function newAuthorizeRequest($type, $typeId, $authParams = [])
@ -160,7 +168,9 @@ class AuthCodeGrant extends AbstractGrant
/** /**
* Complete the auth code grant * Complete the auth code grant
*
* @return array * @return array
*
* @throws * @throws
*/ */
public function completeFlow() public function completeFlow()

View File

@ -25,31 +25,37 @@ class ClientCredentialsGrant extends AbstractGrant
{ {
/** /**
* Grant identifier * Grant identifier
*
* @var string * @var string
*/ */
protected $identifier = 'client_credentials'; protected $identifier = 'client_credentials';
/** /**
* Response type * Response type
*
* @var string * @var string
*/ */
protected $responseType = null; protected $responseType = null;
/** /**
* AuthServer instance * AuthServer instance
*
* @var \League\OAuth2\Server\AuthorizationServer * @var \League\OAuth2\Server\AuthorizationServer
*/ */
protected $server = null; protected $server = null;
/** /**
* Access token expires in override * Access token expires in override
*
* @var int * @var int
*/ */
protected $accessTokenTTL = null; protected $accessTokenTTL = null;
/** /**
* Complete the client credentials grant * Complete the client credentials grant
*
* @return array * @return array
*
* @throws * @throws
*/ */
public function completeFlow() public function completeFlow()

View File

@ -20,32 +20,39 @@ interface GrantTypeInterface
{ {
/** /**
* Return the identifier * Return the identifier
*
* @return string * @return string
*/ */
public function getIdentifier(); public function getIdentifier();
/** /**
* Return the identifier * Return the identifier
* @param string $identifier *
* @param string $identifier
*
* @return self * @return self
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);
/** /**
* Return the response type * Return the response type
*
* @return string * @return string
*/ */
public function getResponseType(); public function getResponseType();
/** /**
* Inject the authorization server into the grant * Inject the authorization server into the grant
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance *
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance
*
* @return self * @return self
*/ */
public function setAuthorizationServer(AuthorizationServer $server); public function setAuthorizationServer(AuthorizationServer $server);
/** /**
* Complete the grant flow * Complete the grant flow
*
* @return array * @return array
*/ */
public function completeFlow(); public function completeFlow();

View File

@ -26,31 +26,37 @@ class PasswordGrant extends AbstractGrant
{ {
/** /**
* Grant identifier * Grant identifier
*
* @var string * @var string
*/ */
protected $identifier = 'password'; protected $identifier = 'password';
/** /**
* Response type * Response type
*
* @var string * @var string
*/ */
protected $responseType; protected $responseType;
/** /**
* Callback to authenticate a user's name and password * Callback to authenticate a user's name and password
*
* @var callable * @var callable
*/ */
protected $callback; protected $callback;
/** /**
* Access token expires in override * Access token expires in override
*
* @var int * @var int
*/ */
protected $accessTokenTTL; protected $accessTokenTTL;
/** /**
* Set the callback to verify a user's username and password * Set the callback to verify a user's username and password
* @param callable $callback The callback function *
* @param callable $callback The callback function
*
* @return void * @return void
*/ */
public function setVerifyCredentialsCallback(callable $callback) public function setVerifyCredentialsCallback(callable $callback)
@ -60,7 +66,9 @@ class PasswordGrant extends AbstractGrant
/** /**
* Return the callback function * Return the callback function
*
* @return callable * @return callable
*
* @throws * @throws
*/ */
protected function getVerifyCredentialsCallback() protected function getVerifyCredentialsCallback()
@ -74,7 +82,9 @@ class PasswordGrant extends AbstractGrant
/** /**
* Complete the password grant * Complete the password grant
*
* @return array * @return array
*
* @throws * @throws
*/ */
public function completeFlow() public function completeFlow()

View File

@ -30,13 +30,16 @@ class RefreshTokenGrant extends AbstractGrant
/** /**
* Refresh token TTL (default = 604800 | 1 week) * Refresh token TTL (default = 604800 | 1 week)
*
* @var integer * @var integer
*/ */
protected $refreshTokenTTL = 604800; protected $refreshTokenTTL = 604800;
/** /**
* Set the TTL of the refresh token * Set the TTL of the refresh token
* @param int $refreshTokenTTL *
* @param int $refreshTokenTTL
*
* @return void * @return void
*/ */
public function setRefreshTokenTTL($refreshTokenTTL) public function setRefreshTokenTTL($refreshTokenTTL)
@ -46,6 +49,7 @@ class RefreshTokenGrant extends AbstractGrant
/** /**
* Get the TTL of the refresh token * Get the TTL of the refresh token
*
* @return int * @return int
*/ */
public function getRefreshTokenTTL() public function getRefreshTokenTTL()

View File

@ -25,22 +25,26 @@ class ResourceServer extends AbstractServer
{ {
/** /**
* The access token * The access token
*
* @var \League\OAuth2\Server\Entity\AccessTokenEntity * @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
protected $accessToken; protected $accessToken;
/** /**
* The query string key which is used by clients to present the access token (default: access_token) * The query string key which is used by clients to present the access token (default: access_token)
*
* @var string * @var string
*/ */
protected $tokenKey = 'access_token'; protected $tokenKey = 'access_token';
/** /**
* Initialise the resource server * Initialise the resource server
* @param SessionInterface $sessionStorage *
* @param AccessTokenInterface $accessTokenStorage * @param SessionInterface $sessionStorage
* @param ClientInterface $clientStorage * @param AccessTokenInterface $accessTokenStorage
* @param ScopeInterface $scopeStorage * @param ClientInterface $clientStorage
* @param ScopeInterface $scopeStorage
*
* @return self * @return self
*/ */
public function __construct( public function __construct(
@ -64,7 +68,9 @@ class ResourceServer extends AbstractServer
/** /**
* Sets the query string key for the access token. * Sets the query string key for the access token.
*
* @param string $key The new query string key * @param string $key The new query string key
*
* @return self * @return self
*/ */
public function setIdKey($key) public function setIdKey($key)
@ -76,6 +82,7 @@ class ResourceServer extends AbstractServer
/** /**
* Gets the access token * Gets the access token
*
* @return \League\OAuth2\Server\Entity\AccessTokenEntity * @return \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
public function getAccessToken() public function getAccessToken()
@ -85,7 +92,8 @@ class ResourceServer extends AbstractServer
/** /**
* Checks if the access token is valid or not * Checks if the access token is valid or not
* @param bool $headersOnly Limit Access Token to Authorization header only *
* @param bool $headersOnly Limit Access Token to Authorization header only
* @param AccessTokenEntity|null $accessToken Access Token * @param AccessTokenEntity|null $accessToken Access Token
* *
* @return bool * @return bool
@ -117,8 +125,11 @@ class ResourceServer extends AbstractServer
/** /**
* Reads in the access token from the headers * Reads in the access token from the headers
*
* @param bool $headersOnly Limit Access Token to Authorization header only * @param bool $headersOnly Limit Access Token to Authorization header only
*
* @throws Exception\InvalidRequestException Thrown if there is no access token presented * @throws Exception\InvalidRequestException Thrown if there is no access token presented
*
* @return string * @return string
*/ */
public function determineAccessToken($headersOnly = false) public function determineAccessToken($headersOnly = false)

View File

@ -20,13 +20,16 @@ abstract class AbstractStorage implements StorageInterface
{ {
/** /**
* Server * Server
*
* @var \League\OAuth2\Server\AbstractServer $server * @var \League\OAuth2\Server\AbstractServer $server
*/ */
protected $server; protected $server;
/** /**
* Set the server * Set the server
*
* @param \League\OAuth2\Server\AbstractServer $server * @param \League\OAuth2\Server\AbstractServer $server
*
* @return self * @return self
*/ */
public function setServer(AbstractServer $server) public function setServer(AbstractServer $server)
@ -38,6 +41,7 @@ abstract class AbstractStorage implements StorageInterface
/** /**
* Return the server * Return the server
*
* @return \League\OAuth2\Server\AbstractServer * @return \League\OAuth2\Server\AbstractServer
*/ */
protected function getServer() protected function getServer()

View File

@ -21,38 +21,48 @@ interface AccessTokenInterface extends StorageInterface
{ {
/** /**
* Get an instance of Entity\AccessTokenEntity * Get an instance of Entity\AccessTokenEntity
* @param string $token The access token *
* @param string $token The access token
*
* @return \League\OAuth2\Server\Entity\AccessTokenEntity * @return \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
public function get($token); public function get($token);
/** /**
* Get the scopes for an access token * Get the scopes for an access token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token *
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token
*
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
*/ */
public function getScopes(AccessTokenEntity $token); public function getScopes(AccessTokenEntity $token);
/** /**
* Creates a new access token * Creates a new access token
* @param string $token The access token *
* @param integer $expireTime The expire time expressed as a unix timestamp * @param string $token The access token
* @param string|integer $sessionId The session ID * @param integer $expireTime The expire time expressed as a unix timestamp
* @param string|integer $sessionId The session ID
*
* @return void * @return void
*/ */
public function create($token, $expireTime, $sessionId); public function create($token, $expireTime, $sessionId);
/** /**
* Associate a scope with an acess token * Associate a scope with an acess token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token *
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
*
* @return void * @return void
*/ */
public function associateScope(AccessTokenEntity $token, ScopeEntity $scope); public function associateScope(AccessTokenEntity $token, ScopeEntity $scope);
/** /**
* Delete an access token * Delete an access token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete *
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete
*
* @return void * @return void
*/ */
public function delete(AccessTokenEntity $token); public function delete(AccessTokenEntity $token);

View File

@ -21,39 +21,49 @@ interface AuthCodeInterface extends StorageInterface
{ {
/** /**
* Get the auth code * Get the auth code
* @param string $code *
* @param string $code
*
* @return \League\OAuth2\Server\Entity\AuthCodeEntity * @return \League\OAuth2\Server\Entity\AuthCodeEntity
*/ */
public function get($code); public function get($code);
/** /**
* Create an auth code. * Create an auth code.
*
* @param string $token The token ID * @param string $token The token ID
* @param integer $expireTime Token expire time * @param integer $expireTime Token expire time
* @param integer $sessionId Session identifier * @param integer $sessionId Session identifier
* @param string $redirectUri Client redirect uri * @param string $redirectUri Client redirect uri
*
* @return void * @return void
*/ */
public function create($token, $expireTime, $sessionId, $redirectUri); public function create($token, $expireTime, $sessionId, $redirectUri);
/** /**
* Get the scopes for an access token * Get the scopes for an access token
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code *
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity * @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code
*
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
*/ */
public function getScopes(AuthCodeEntity $token); public function getScopes(AuthCodeEntity $token);
/** /**
* Associate a scope with an acess token * Associate a scope with an acess token
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code *
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope * @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
*
* @return void * @return void
*/ */
public function associateScope(AuthCodeEntity $token, ScopeEntity $scope); public function associateScope(AuthCodeEntity $token, ScopeEntity $scope);
/** /**
* Delete an access token * Delete an access token
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The access token to delete *
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The access token to delete
*
* @return void * @return void
*/ */
public function delete(AuthCodeEntity $token); public function delete(AuthCodeEntity $token);

View File

@ -20,17 +20,21 @@ interface ClientInterface extends StorageInterface
{ {
/** /**
* Validate a client * Validate a client
* @param string $clientId The client's ID *
* @param string $clientSecret The client's secret (default = "null") * @param string $clientId The client's ID
* @param string $redirectUri The client's redirect URI (default = "null") * @param string $clientSecret The client's secret (default = "null")
* @param string $grantType The grant type used (default = "null") * @param string $redirectUri The client's redirect URI (default = "null")
* @param string $grantType The grant type used (default = "null")
*
* @return \League\OAuth2\Server\Entity\ClientEntity * @return \League\OAuth2\Server\Entity\ClientEntity
*/ */
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null); public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null);
/** /**
* Get the client associated with a session * Get the client associated with a session
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session *
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session
*
* @return \League\OAuth2\Server\Entity\ClientEntity * @return \League\OAuth2\Server\Entity\ClientEntity
*/ */
public function getBySession(SessionEntity $session); public function getBySession(SessionEntity $session);

View File

@ -20,23 +20,29 @@ interface RefreshTokenInterface extends StorageInterface
{ {
/** /**
* Return a new instance of \League\OAuth2\Server\Entity\RefreshTokenEntity * Return a new instance of \League\OAuth2\Server\Entity\RefreshTokenEntity
* @param string $token *
* @param string $token
*
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity * @return \League\OAuth2\Server\Entity\RefreshTokenEntity
*/ */
public function get($token); public function get($token);
/** /**
* Create a new refresh token_name * Create a new refresh token_name
* @param string $token *
* @param integer $expireTime * @param string $token
* @param string $accessToken * @param integer $expireTime
* @param string $accessToken
*
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity * @return \League\OAuth2\Server\Entity\RefreshTokenEntity
*/ */
public function create($token, $expireTime, $accessToken); public function create($token, $expireTime, $accessToken);
/** /**
* Delete the refresh token * Delete the refresh token
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $token *
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $token
*
* @return void * @return void
*/ */
public function delete(RefreshTokenEntity $token); public function delete(RefreshTokenEntity $token);

View File

@ -18,9 +18,11 @@ interface ScopeInterface extends StorageInterface
{ {
/** /**
* Return information about a scope * Return information about a scope
* @param string $scope The scope *
* @param string $grantType The grant type used in the request (default = "null") * @param string $scope The scope
* @param string $clientId The client sending the request (default = "null") * @param string $grantType The grant type used in the request (default = "null")
* @param string $clientId The client sending the request (default = "null")
*
* @return \League\OAuth2\Server\Entity\ScopeEntity * @return \League\OAuth2\Server\Entity\ScopeEntity
*/ */
public function get($scope, $grantType = null, $clientId = null); public function get($scope, $grantType = null, $clientId = null);

View File

@ -23,39 +23,49 @@ interface SessionInterface extends StorageInterface
{ {
/** /**
* Get a session from an access token * Get a session from an access token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken The access token *
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken The access token
*
* @return \League\OAuth2\Server\Entity\SessionEntity * @return \League\OAuth2\Server\Entity\SessionEntity
*/ */
public function getByAccessToken(AccessTokenEntity $accessToken); public function getByAccessToken(AccessTokenEntity $accessToken);
/** /**
* Get a session from an auth code * Get a session from an auth code
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $authCode The auth code *
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $authCode The auth code
*
* @return \League\OAuth2\Server\Entity\SessionEntity * @return \League\OAuth2\Server\Entity\SessionEntity
*/ */
public function getByAuthCode(AuthCodeEntity $authCode); public function getByAuthCode(AuthCodeEntity $authCode);
/** /**
* Get a session's scopes * Get a session's scopes
*
* @param \League\OAuth2\Server\Entity\SessionEntity * @param \League\OAuth2\Server\Entity\SessionEntity
*
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity * @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
*/ */
public function getScopes(SessionEntity $session); public function getScopes(SessionEntity $session);
/** /**
* Create a new session * Create a new session
* @param string $ownerType Session owner's type (user, client) *
* @param string $ownerId Session owner's ID * @param string $ownerType Session owner's type (user, client)
* @param string $clientId Client ID * @param string $ownerId Session owner's ID
* @param string $clientRedirectUri Client redirect URI (default = null) * @param string $clientId Client ID
* @param string $clientRedirectUri Client redirect URI (default = null)
*
* @return integer The session's ID * @return integer The session's ID
*/ */
public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null); public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null);
/** /**
* Associate a scope with a session * Associate a scope with a session
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session *
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope * @param \League\OAuth2\Server\Entity\SessionEntity $session The session
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
*
* @return void * @return void
*/ */
public function associateScope(SessionEntity $session, ScopeEntity $scope); public function associateScope(SessionEntity $session, ScopeEntity $scope);

View File

@ -20,6 +20,7 @@ interface StorageInterface
{ {
/** /**
* Set the server * Set the server
*
* @param \League\OAuth2\Server\AbstractServer $server * @param \League\OAuth2\Server\AbstractServer $server
*/ */
public function setServer(AbstractServer $server); public function setServer(AbstractServer $server);

View File

@ -18,18 +18,21 @@ abstract class AbstractTokenType
{ {
/** /**
* Response array * Response array
*
* @var array * @var array
*/ */
protected $response = []; protected $response = [];
/** /**
* Server * Server
*
* @var \League\OAuth2\Server\AbstractServer $server * @var \League\OAuth2\Server\AbstractServer $server
*/ */
protected $server; protected $server;
/** /**
* Server * Server
*
* @var \League\OAuth2\Server\Entity\SessionEntity $session * @var \League\OAuth2\Server\Entity\SessionEntity $session
*/ */
protected $session; protected $session;

View File

@ -19,19 +19,23 @@ interface TokenTypeInterface
{ {
/** /**
* Generate a response * Generate a response
*
* @return array * @return array
*/ */
public function generateResponse(); public function generateResponse();
/** /**
* Set the server * Set the server
*
* @param \League\OAuth2\Server\AbstractServer $server * @param \League\OAuth2\Server\AbstractServer $server
*
* @return self * @return self
*/ */
public function setServer(AbstractServer $server); public function setServer(AbstractServer $server);
/** /**
* Set a key/value response pair * Set a key/value response pair
*
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
*/ */
@ -39,20 +43,25 @@ interface TokenTypeInterface
/** /**
* Get a key from the response array * Get a key from the response array
* @param string $key *
* @param string $key
*
* @return mixed * @return mixed
*/ */
public function getParam($key); public function getParam($key);
/** /**
* @param \League\OAuth2\Server\Entity\SessionEntity $session * @param \League\OAuth2\Server\Entity\SessionEntity $session
*
* @return self * @return self
*/ */
public function setSession(SessionEntity $session); public function setSession(SessionEntity $session);
/** /**
* Determine the access token in the authorization header * Determine the access token in the authorization header
* @param \Symfony\Component\HttpFoundation\Request $request *
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return string * @return string
*/ */
public function determineAccessTokenInHeader(Request $request); public function determineAccessTokenInHeader(Request $request);

View File

@ -21,7 +21,7 @@ class DefaultAlgorithm implements KeyAlgorithmInterface
$stripped = ''; $stripped = '';
do { do {
$bytes = openssl_random_pseudo_bytes($len, $strong); $bytes = openssl_random_pseudo_bytes($len, $strong);
// We want to stop execution if the key fails because, well, that is bad. // We want to stop execution if the key fails because, well, that is bad.
if ($bytes === false || $strong === false) { if ($bytes === false || $strong === false) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
@ -30,6 +30,7 @@ class DefaultAlgorithm implements KeyAlgorithmInterface
} }
$stripped .= str_replace(['/', '+', '='], '', base64_encode($bytes)); $stripped .= str_replace(['/', '+', '='], '', base64_encode($bytes));
} while (strlen($stripped) < $len); } while (strlen($stripped) < $len);
return substr($stripped, 0, $len); return substr($stripped, 0, $len);
} }
} }

View File

@ -15,7 +15,9 @@ interface KeyAlgorithmInterface
{ {
/** /**
* Generate a new unique code * Generate a new unique code
* @param integer $len Length of the generated code *
* @param integer $len Length of the generated code
*
* @return string * @return string
*/ */
public function generate($len); public function generate($len);

View File

@ -18,9 +18,11 @@ class RedirectUri
{ {
/** /**
* Generate a new redirect uri * Generate a new redirect uri
* @param string $uri The base URI *
* @param array $params The query string parameters * @param string $uri The base URI
* @param string $queryDelimeter The query string delimeter (default: "?") * @param array $params The query string parameters
* @param string $queryDelimeter The query string delimeter (default: "?")
*
* @return string The updated URI * @return string The updated URI
*/ */
public static function make($uri, $params = [], $queryDelimeter = '?') public static function make($uri, $params = [], $queryDelimeter = '?')

View File

@ -23,7 +23,9 @@ class SecureKey
/** /**
* Generate a new unique code * Generate a new unique code
* @param integer $len Length of the generated code *
* @param integer $len Length of the generated code
*
* @return string * @return string
*/ */
public static function generate($len = 40) public static function generate($len = 40)

View File

@ -2,10 +2,10 @@
namespace LeagueTests\Entity; namespace LeagueTests\Entity;
use LeagueTests\Stubs\StubAbstractTokenEntity;
use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Entity\SessionEntity;
use LeagueTests\Stubs\StubAbstractTokenEntity;
use Mockery as M; use Mockery as M;
class AbstractTokenEntityTest extends \PHPUnit_Framework_TestCase class AbstractTokenEntityTest extends \PHPUnit_Framework_TestCase

View File

@ -2,12 +2,12 @@
namespace LeagueTests\Grant; namespace LeagueTests\Grant;
use LeagueTests\Stubs\StubAbstractGrant;
use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Exception\InvalidRequestException; use League\OAuth2\Server\Exception\InvalidRequestException;
use League\OAuth2\Server\Grant; use League\OAuth2\Server\Grant;
use LeagueTests\Stubs\StubAbstractGrant;
use Mockery as M; use Mockery as M;
class AbstractGrantTest extends \PHPUnit_Framework_TestCase class AbstractGrantTest extends \PHPUnit_Framework_TestCase

View File

@ -288,7 +288,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
public function testCompleteFlowExpiredRefreshToken() public function testCompleteFlowExpiredRefreshToken()
{ {
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRefreshException'); $this->setExpectedException('League\OAuth2\Server\Exception\InvalidRefreshException');
$_POST = [ $_POST = [
'grant_type' => 'refresh_token', 'grant_type' => 'refresh_token',
'client_id' => 'testapp', 'client_id' => 'testapp',