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

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

View File

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

View File

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

View File

@@ -20,32 +20,39 @@ interface GrantTypeInterface
{
/**
* Return the identifier
*
* @return string
*/
public function getIdentifier();
/**
* Return the identifier
* @param string $identifier
*
* @param string $identifier
*
* @return self
*/
public function setIdentifier($identifier);
/**
* Return the response type
*
* @return string
*/
public function getResponseType();
/**
* 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
*/
public function setAuthorizationServer(AuthorizationServer $server);
/**
* Complete the grant flow
*
* @return array
*/
public function completeFlow();

View File

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

View File

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