Skip to content

Commit

Permalink
Moved some grant related functions into a trait to reduce duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbilbie committed Dec 2, 2013
1 parent 954ff19 commit 031cf30
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 124 deletions.
30 changes: 2 additions & 28 deletions src/League/OAuth2/Server/Grant/AuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class AuthCode implements GrantTypeInterface {

use GrantTrait;

/**
* Grant identifier
* @var string
Expand Down Expand Up @@ -64,34 +66,6 @@ public function __construct(Authorization $authServer)
$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
Expand Down
2 changes: 2 additions & 0 deletions src/League/OAuth2/Server/Grant/ClientCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class ClientCredentials implements GrantTypeInterface {

use GrantTrait;

/**
* Grant identifier
* @var string
Expand Down
45 changes: 45 additions & 0 deletions src/League/OAuth2/Server/Grant/GrantTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* OAuth 2.0 Client credentials grant
*
* @package php-loep/oauth2-server
* @author Alex Bilbie <[email protected]>
* @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;
}

}
12 changes: 0 additions & 12 deletions src/League/OAuth2/Server/Grant/GrantTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
30 changes: 2 additions & 28 deletions src/League/OAuth2/Server/Grant/Implicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class Implicit implements GrantTypeInterface {

use GrantTrait;

/**
* Grant identifier
* @var string
Expand Down Expand Up @@ -58,34 +60,6 @@ public function __construct(Authorization $authServer)
$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
Expand Down
30 changes: 2 additions & 28 deletions src/League/OAuth2/Server/Grant/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class Password implements GrantTypeInterface {

use GrantTrait;

/**
* Grant identifier
* @var string
Expand Down Expand Up @@ -64,34 +66,6 @@ public function __construct(Authorization $authServer)
$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
Expand Down
30 changes: 2 additions & 28 deletions src/League/OAuth2/Server/Grant/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class RefreshToken implements GrantTypeInterface {

use GrantTrait;

/**
* Grant identifier
* @var string
Expand Down Expand Up @@ -70,34 +72,6 @@ public function __construct(Authorization $authServer)
$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
Expand Down

0 comments on commit 031cf30

Please sign in to comment.