Moved some grant related functions into a trait to reduce duplicate code

This commit is contained in:
Alex Bilbie 2013-12-02 18:42:54 +00:00
parent 954ff19823
commit 031cf3064a
7 changed files with 55 additions and 124 deletions

View File

@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class AuthCode implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@ -64,34 +66,6 @@ class AuthCode implements GrantTypeInterface {
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Override the default access token expire time
* @param int $authTokenTTL

View File

@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class ClientCredentials implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string

View File

@ -0,0 +1,45 @@
<?php
/**
* OAuth 2.0 Client credentials grant
*
* @package php-loep/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 PHP League of Extraordinary Packages
* @license http://mit-license.org/
* @link http://github.com/php-loep/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
trait GrantTrait {
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return self
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
return $this;
}
}

View File

@ -28,18 +28,6 @@ interface GrantTypeInterface
*/
public function __construct(Authorization $authServer);
/**
* Returns the grant identifier (used to validate grant_type in League\OAuth2\Server\Authorization::issueAccessToken())
* @return string
*/
public function getIdentifier();
/**
* Returns the response type (used to validate response_type in League\OAuth2\Server\Grant\AuthCode::checkAuthoriseParams())
* @return null|string
*/
public function getResponseType();
/**
* Complete the grant flow
*

View File

@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class Implicit implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@ -58,34 +60,6 @@ class Implicit implements GrantTypeInterface {
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Complete the client credentials grant
* @param null|array $inputParams

View File

@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class Password implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@ -64,34 +66,6 @@ class Password implements GrantTypeInterface {
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Set the callback to verify a user's username and password
* @param callable $callback The callback function

View File

@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class RefreshToken implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@ -70,34 +72,6 @@ class RefreshToken implements GrantTypeInterface {
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Set the TTL of the refresh token
* @param int $refreshTokenTTL