This commit is contained in:
Graham Campbell
2014-11-08 18:26:12 +00:00
parent 30162c8899
commit 4c1cd04a24
61 changed files with 430 additions and 503 deletions

View File

@@ -11,16 +11,15 @@
namespace League\OAuth2\Server;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\TokenType\TokenTypeInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use Symfony\Component\HttpFoundation\Request;
use League\Event\Emitter;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\TokenType\TokenTypeInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* OAuth 2.0 Resource Server
@@ -98,7 +97,7 @@ abstract class AbstractServer
public function setEventEmitter($emitter = null)
{
if ($emitter === null) {
$this->eventEmitter = new Emitter;
$this->eventEmitter = new Emitter();
} else {
$this->eventEmitter = $emitter;
}

View File

@@ -12,12 +12,6 @@
namespace League\OAuth2\Server;
use League\OAuth2\Server\Grant\GrantTypeInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\TokenType\Bearer;
use Symfony\Component\HttpFoundation\Request;
@@ -76,7 +70,7 @@ class AuthorizationServer extends AbstractServer
public function __construct()
{
// Set Bearer as the default token type
$this->setTokenType(new Bearer);
$this->setTokenType(new Bearer());
parent::__construct();

View File

@@ -11,10 +11,8 @@
namespace League\OAuth2\Server\Entity;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\AbstractServer;
use Symfony\Component\HttpFoundation\ParameterBag;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Util\SecureKey;
/**
* Abstract token class
@@ -170,6 +168,7 @@ abstract class AbstractTokenEntity
if ($this->id === null) {
return '';
}
return $this->id;
}

View File

@@ -56,7 +56,7 @@ class AuthCodeEntity extends AbstractTokenEntity
return $uri.http_build_query([
'code' => $this->getId(),
'state' => $state
'state' => $state,
]);
}

View File

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

View File

@@ -12,8 +12,8 @@
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Exception;
/**
@@ -108,7 +108,7 @@ abstract class AbstractGrant implements GrantTypeInterface
/**
* 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)
@@ -120,11 +120,11 @@ 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 \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required
*/
public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null)
{

View File

@@ -11,15 +11,15 @@
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Request;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Request;
use League\OAuth2\Server\Util\SecureKey;
/**
* Auth code grant class
@@ -234,7 +234,7 @@ class AuthCodeGrant extends AbstractGrant
}
foreach ($session->getScopes() as $scope) {
$accessToken->associateScope($scope);
$accessToken->associateScope($scope);
}
$this->server->getTokenType()->setSession($session);

View File

@@ -14,9 +14,9 @@ namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Event;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Client credentials grant class
@@ -53,7 +53,7 @@ class ClientCredentialsGrant extends AbstractGrant
*/
public function completeFlow()
{
// Get the required params
// Get the required params
$clientId = $this->server->getRequest()->request->get('client_id', null);
if (is_null($clientId)) {
$clientId = $this->server->getRequest()->getUser();
@@ -99,11 +99,11 @@ class ClientCredentialsGrant extends AbstractGrant
// Associate scopes with the session and access token
foreach ($scopes as $scope) {
$session->associateScope($scope);
$session->associateScope($scope);
}
foreach ($session->getScopes() as $scope) {
$accessToken->associateScope($scope);
$accessToken->associateScope($scope);
}
// Save everything

View File

@@ -11,13 +11,13 @@
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Event;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Password grant class
@@ -141,11 +141,11 @@ class PasswordGrant extends AbstractGrant
// Associate scopes with the session and access token
foreach ($scopes as $scope) {
$session->associateScope($scope);
$session->associateScope($scope);
}
foreach ($session->getScopes() as $scope) {
$accessToken->associateScope($scope);
$accessToken->associateScope($scope);
}
$this->server->getTokenType()->setSession($session);

View File

@@ -11,13 +11,13 @@
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Request;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Event;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Request;
use League\OAuth2\Server\Util\SecureKey;
/**
* Referesh token grant

View File

@@ -11,13 +11,12 @@
namespace League\OAuth2\Server;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\TokenType\Bearer;
use League\OAuth2\Server\Exception;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -57,7 +56,7 @@ class ResourceServer extends AbstractServer
$this->setScopeStorage($scopeStorage);
// Set Bearer as the default token type
$this->setTokenType(new Bearer);
$this->setTokenType(new Bearer());
parent::__construct();
@@ -101,13 +100,13 @@ class ResourceServer extends AbstractServer
// Ensure the access token exists
if (!$this->accessToken instanceof AccessTokenEntity) {
throw new Exception\AccessDeniedException;
throw new Exception\AccessDeniedException();
}
// Check the access token hasn't expired
// Ensure the auth code hasn't expired
if ($this->accessToken->isExpired() === true) {
throw new Exception\AccessDeniedException;
throw new Exception\AccessDeniedException();
}
return true;

View File

@@ -11,9 +11,8 @@
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AbstractTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
/**

View File

@@ -13,8 +13,8 @@ namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
/**
* Session storage interface

View File

@@ -11,9 +11,9 @@
namespace League\OAuth2\Server\TokenType;
use Symfony\Component\HttpFoundation\Request;
use League\OAuth2\Server\AbstractServer;
use League\OAuth2\Server\Entity\SessionEntity;
use Symfony\Component\HttpFoundation\Request;
abstract class AbstractTokenType
{
@@ -42,6 +42,7 @@ abstract class AbstractTokenType
public function setServer(AbstractServer $server)
{
$this->server = $server;
return $this;
}
@@ -52,6 +53,7 @@ abstract class AbstractTokenType
public function setSession(SessionEntity $session)
{
$this->session = $session;
return $this;
}

View File

@@ -23,7 +23,7 @@ class Bearer extends AbstractTokenType implements TokenTypeInterface
$return = [
'access_token' => $this->getParam('access_token'),
'token_type' => 'Bearer',
'expires_in' => $this->getParam('expires_in')
'expires_in' => $this->getParam('expires_in'),
];
if (!is_null($this->getParam('refresh_token'))) {

View File

@@ -30,6 +30,6 @@ class DefaultAlgorithm implements KeyAlgorithmInterface
// @codeCoverageIgnoreEnd
}
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $len);
return substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $len);
}
}

View File

@@ -23,7 +23,7 @@ class RedirectUri
* @param string $queryDelimeter The query string delimeter (default: "?")
* @return string The updated URI
*/
public static function make($uri, $params = array(), $queryDelimeter = '?')
public static function make($uri, $params = [], $queryDelimeter = '?')
{
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&';