mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6157bd77ca | ||
|
|
76de634f2b | ||
|
|
cfada388db | ||
|
|
2f971dc77f | ||
|
|
ae7b7e9aa9 | ||
|
|
bed6c3287e | ||
|
|
f83e5a8731 | ||
|
|
35369038db | ||
|
|
6a1f927a6c | ||
|
|
b2c0933ee6 | ||
|
|
3104d13eba | ||
|
|
8b1f3ef193 | ||
|
|
1ff885cff1 |
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 4.0.2 (released 2014-11-21)
|
||||
|
||||
* Improved interfaces (Issue #255)
|
||||
* Learnt how to spell delimiter and so `getScopeDelimiter()` and `setScopeDelimiter()` methods have been renamed
|
||||
* Docblock improvements (Issue #254)
|
||||
|
||||
## 4.0.1 (released 2014-11-09)
|
||||
|
||||
* Alias the master branch in composer.json (Issue #243)
|
||||
|
||||
@@ -55,10 +55,5 @@
|
||||
"psr-4": {
|
||||
"LeagueTests\\": "tests/unit/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use League\OAuth2\Server\Entity\AbstractTokenEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
|
||||
class AccessTokenStorage extends Adapter implements AccessTokenInterface
|
||||
class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace RelationalExample\Storage;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
||||
|
||||
class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
||||
class AuthCodeStorage extends AbstractStorage implements AuthCodeInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace RelationalExample\Storage;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\ClientInterface;
|
||||
|
||||
class ClientStorage extends Adapter implements ClientInterface
|
||||
class ClientStorage extends AbstractStorage implements ClientInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -4,10 +4,10 @@ namespace RelationalExample\Storage;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
||||
|
||||
class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
|
||||
class RefreshTokenStorage extends AbstractStorage implements RefreshTokenInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -4,10 +4,10 @@ namespace RelationalExample\Storage;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
|
||||
class ScopeStorage extends Adapter implements ScopeInterface
|
||||
class ScopeStorage extends AbstractStorage implements ScopeInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -7,10 +7,10 @@ use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
|
||||
class SessionStorage extends Adapter implements SessionInterface
|
||||
class SessionStorage extends AbstractStorage implements SessionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -188,7 +188,7 @@ abstract class AbstractServer
|
||||
|
||||
/**
|
||||
* Set the refresh token storage
|
||||
* @param \League\OAuth2\Server\Storage\RefreshTokenInteface $storage
|
||||
* @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage
|
||||
* @return self
|
||||
*/
|
||||
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
|
||||
@@ -201,7 +201,7 @@ abstract class AbstractServer
|
||||
|
||||
/**
|
||||
* Set the auth code storage
|
||||
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $authCode
|
||||
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage
|
||||
* @return self
|
||||
*/
|
||||
public function setAuthCodeStorage(AuthCodeInterface $storage)
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace League\OAuth2\Server;
|
||||
|
||||
use League\OAuth2\Server\Grant\GrantTypeInterface;
|
||||
use League\OAuth2\Server\TokenType\Bearer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* OAuth 2.0 authorization server class
|
||||
@@ -25,7 +24,7 @@ class AuthorizationServer extends AbstractServer
|
||||
* The OAuth 2 specification states it should be a space but most use a comma
|
||||
* @var string
|
||||
*/
|
||||
protected $scopeDelimeter = ' ';
|
||||
protected $scopeDelimiter = ' ';
|
||||
|
||||
/**
|
||||
* The TTL (time to live) of an access token in seconds (default: 3600)
|
||||
@@ -121,7 +120,7 @@ class AuthorizationServer extends AbstractServer
|
||||
}
|
||||
|
||||
/**
|
||||
* Require the "scope" paremter in checkAuthoriseParams()
|
||||
* Require the "scope" parameter in checkAuthoriseParams()
|
||||
* @param boolean $require
|
||||
* @return self
|
||||
*/
|
||||
@@ -144,7 +143,7 @@ class AuthorizationServer extends AbstractServer
|
||||
/**
|
||||
* Default scope to be used if none is provided and requireScopeParam() is false
|
||||
* @param string $default Name of the default scope
|
||||
* @param self
|
||||
* @return self
|
||||
*/
|
||||
public function setDefaultScope($default = null)
|
||||
{
|
||||
@@ -164,8 +163,7 @@ class AuthorizationServer extends AbstractServer
|
||||
|
||||
/**
|
||||
* Require the "state" paremter in checkAuthoriseParams()
|
||||
* @param boolean $require
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function stateParamRequired()
|
||||
{
|
||||
@@ -175,7 +173,7 @@ class AuthorizationServer extends AbstractServer
|
||||
/**
|
||||
* Require the "state" paremter in checkAuthoriseParams()
|
||||
* @param boolean $require
|
||||
* @return void
|
||||
* @return self
|
||||
*/
|
||||
public function requireStateParam($require = true)
|
||||
{
|
||||
@@ -185,21 +183,22 @@ class AuthorizationServer extends AbstractServer
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scope delimeter
|
||||
* Get the scope delimiter
|
||||
* @return string The scope delimiter (default: ",")
|
||||
*/
|
||||
public function getScopeDelimeter()
|
||||
public function getScopeDelimiter()
|
||||
{
|
||||
return $this->scopeDelimeter;
|
||||
return $this->scopeDelimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scope delimiter
|
||||
* @param string $scopeDelimeter
|
||||
* @param string $scopeDelimiter
|
||||
* @return self
|
||||
*/
|
||||
public function setScopeDelimeter($scopeDelimeter = ' ')
|
||||
public function setScopeDelimiter($scopeDelimiter = ' ')
|
||||
{
|
||||
$this->scopeDelimeter = $scopeDelimeter;
|
||||
$this->scopeDelimiter = $scopeDelimiter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -216,6 +215,7 @@ class AuthorizationServer extends AbstractServer
|
||||
/**
|
||||
* Set the TTL for an access token
|
||||
* @param int $accessTokenTTL The new TTL
|
||||
* @return self
|
||||
*/
|
||||
public function setAccessTokenTTL($accessTokenTTL = 3600)
|
||||
{
|
||||
@@ -227,6 +227,7 @@ class AuthorizationServer extends AbstractServer
|
||||
/**
|
||||
* Issue an access token
|
||||
* @return array Authorise request parameters
|
||||
* @throws
|
||||
*/
|
||||
public function issueAccessToken()
|
||||
{
|
||||
@@ -246,8 +247,9 @@ class AuthorizationServer extends AbstractServer
|
||||
|
||||
/**
|
||||
* Return a grant type class
|
||||
* @param string $grantType The grant type identifer
|
||||
* @param string $grantType The grant type identifier
|
||||
* @return Grant\GrantTypeInterface
|
||||
* @throws
|
||||
*/
|
||||
public function getGrantType($grantType)
|
||||
{
|
||||
|
||||
@@ -105,7 +105,7 @@ abstract class AbstractTokenEntity
|
||||
|
||||
/**
|
||||
* Set token ID
|
||||
* @param string $token Token ID
|
||||
* @param string $id Token ID
|
||||
* @return self
|
||||
*/
|
||||
public function setId($id = null)
|
||||
|
||||
@@ -47,7 +47,7 @@ class AccessTokenEntity extends AbstractTokenEntity
|
||||
|
||||
/**
|
||||
* Return all scopes associated with the access token
|
||||
* @return \League\OAuth2\Server\Entity\Scope[]
|
||||
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||
*/
|
||||
public function getScopes()
|
||||
{
|
||||
|
||||
@@ -77,7 +77,7 @@ class AuthCodeEntity extends AbstractTokenEntity
|
||||
|
||||
/**
|
||||
* Return all scopes associated with the session
|
||||
* @return \League\OAuth2\Server\Entity\Scope[]
|
||||
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||
*/
|
||||
public function getScopes()
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ trait EntityTrait
|
||||
/**
|
||||
* Hydrate an entity with properites
|
||||
* @param array $properties
|
||||
* @return self
|
||||
*/
|
||||
public function hydrate(array $properties)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
||||
|
||||
/**
|
||||
* Set the ID of the associated access token
|
||||
* @param string $accessToken
|
||||
* @param string $accessTokenId
|
||||
* @return self
|
||||
*/
|
||||
public function setAccessTokenId($accessTokenId)
|
||||
@@ -42,7 +42,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
||||
|
||||
/**
|
||||
* Associate an access token
|
||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
|
||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessTokenEntity
|
||||
* @return self
|
||||
*/
|
||||
public function setAccessToken(AccessTokenEntity $accessTokenEntity)
|
||||
@@ -54,7 +54,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
||||
|
||||
/**
|
||||
* Return access token
|
||||
* @return AccessToken
|
||||
* @return AccessTokenEntity
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
namespace League\OAuth2\Server\Entity;
|
||||
|
||||
use League\OAuth2\Server\AbstractServer;
|
||||
use League\OAuth2\Server\Event;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use League\OAuth2\Server\Event\SessionOwnerEvent;
|
||||
|
||||
/**
|
||||
* Session entity grant
|
||||
@@ -137,7 +136,7 @@ class SessionEntity
|
||||
|
||||
/**
|
||||
* Return all scopes associated with the session
|
||||
* @return \League\OAuth2\Server\Entity\Scope[]
|
||||
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||
*/
|
||||
public function getScopes()
|
||||
{
|
||||
@@ -153,11 +152,11 @@ class SessionEntity
|
||||
* @param \League\OAuth2\Server\Entity\Scope[]
|
||||
* @return array
|
||||
*/
|
||||
private function formatScopes($unformated = [])
|
||||
private function formatScopes($unformatted = [])
|
||||
{
|
||||
$scopes = [];
|
||||
if (is_array($unformated)) {
|
||||
foreach ($unformated as $scope) {
|
||||
if (is_array($unformatted)) {
|
||||
foreach ($unformatted as $scope) {
|
||||
if ($scope instanceof ScopeEntity) {
|
||||
$scopes[$scope->getId()] = $scope;
|
||||
}
|
||||
@@ -229,7 +228,7 @@ class SessionEntity
|
||||
$this->ownerType = $type;
|
||||
$this->ownerId = $id;
|
||||
|
||||
$this->server->getEventEmitter()->emit(new Event\SessionOwnerEvent($this));
|
||||
$this->server->getEventEmitter()->emit(new SessionOwnerEvent($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class ClientAuthenticationFailedEvent extends AbstractEvent
|
||||
|
||||
/**
|
||||
* Init the event with a request
|
||||
* @param \Symfony\Component\HttpFoundation\Requesty $request
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ class UserAuthenticationFailedEvent extends AbstractEvent
|
||||
|
||||
/**
|
||||
* Init the event with a request
|
||||
* @param \Symfony\Component\HttpFoundation\Requesty $request
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
use League\OAuth2\Server\Util\RedirectUri;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@@ -36,6 +37,7 @@ class OAuthException extends \Exception
|
||||
|
||||
/**
|
||||
* Throw a new exception
|
||||
* @param string $msg Exception Message
|
||||
*/
|
||||
public function __construct($msg = 'An error occured')
|
||||
{
|
||||
@@ -57,7 +59,7 @@ class OAuthException extends \Exception
|
||||
*/
|
||||
public function getRedirectUri()
|
||||
{
|
||||
return \League\OAuth2\Server\Util\RedirectUri::make(
|
||||
return RedirectUri::make(
|
||||
$this->redirectUri,
|
||||
[
|
||||
'error' => $this->errorType,
|
||||
|
||||
@@ -35,7 +35,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
|
||||
/**
|
||||
* Callback to authenticate a user's name and password
|
||||
* @var function
|
||||
* @var callable
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
@@ -52,8 +52,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
protected $accessTokenTTL;
|
||||
|
||||
/**
|
||||
* Return the identifier
|
||||
* @return string
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIdentifier()
|
||||
{
|
||||
@@ -61,9 +60,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the identifier
|
||||
* @param string $identifier
|
||||
* @return self
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setIdentifier($identifier)
|
||||
{
|
||||
@@ -73,8 +70,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the response type
|
||||
* @return string
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getResponseType()
|
||||
{
|
||||
@@ -107,9 +103,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the authorization server into the grant
|
||||
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance
|
||||
* @return self
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAuthorizationServer(AuthorizationServer $server)
|
||||
{
|
||||
@@ -125,10 +119,11 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
* @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
|
||||
*/
|
||||
public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null)
|
||||
{
|
||||
$scopesList = explode($this->server->getScopeDelimeter(), $scopeParam);
|
||||
$scopesList = explode($this->server->getScopeDelimiter(), $scopeParam);
|
||||
|
||||
for ($i = 0; $i < count($scopesList); $i++) {
|
||||
$scopesList[$i] = trim($scopesList[$i]);
|
||||
|
||||
@@ -18,7 +18,6 @@ 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\Request;
|
||||
use League\OAuth2\Server\Util\SecureKey;
|
||||
|
||||
/**
|
||||
@@ -40,7 +39,7 @@ class AuthCodeGrant extends AbstractGrant
|
||||
|
||||
/**
|
||||
* AuthServer instance
|
||||
* @var AuthServer
|
||||
* @var \League\OAuth2\Server\AuthorizationServer
|
||||
*/
|
||||
protected $server = null;
|
||||
|
||||
@@ -70,6 +69,8 @@ class AuthCodeGrant extends AbstractGrant
|
||||
* Check authorize parameters
|
||||
*
|
||||
* @return array Authorize request parameters
|
||||
*
|
||||
* @throws
|
||||
*/
|
||||
public function checkAuthorizeParams()
|
||||
{
|
||||
@@ -160,6 +161,7 @@ class AuthCodeGrant extends AbstractGrant
|
||||
/**
|
||||
* Complete the auth code grant
|
||||
* @return array
|
||||
* @throws
|
||||
*/
|
||||
public function completeFlow()
|
||||
{
|
||||
@@ -257,7 +259,7 @@ class AuthCodeGrant extends AbstractGrant
|
||||
$accessToken->setSession($session);
|
||||
$accessToken->save();
|
||||
|
||||
if ($this->server->hasGrantType('refresh_token')) {
|
||||
if (isset($refreshToken) && $this->server->hasGrantType('refresh_token')) {
|
||||
$refreshToken->setAccessToken($accessToken);
|
||||
$refreshToken->save();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class ClientCredentialsGrant extends AbstractGrant
|
||||
|
||||
/**
|
||||
* AuthServer instance
|
||||
* @var AuthServer
|
||||
* @var \League\OAuth2\Server\AuthorizationServer
|
||||
*/
|
||||
protected $server = null;
|
||||
|
||||
@@ -50,6 +50,7 @@ class ClientCredentialsGrant extends AbstractGrant
|
||||
/**
|
||||
* Complete the client credentials grant
|
||||
* @return array
|
||||
* @throws
|
||||
*/
|
||||
public function completeFlow()
|
||||
{
|
||||
|
||||
@@ -11,11 +11,39 @@
|
||||
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
|
||||
/**
|
||||
* Grant type interface
|
||||
*/
|
||||
interface GrantTypeInterface
|
||||
{
|
||||
/**
|
||||
* Return the identifier
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Return the 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
|
||||
* @return self
|
||||
*/
|
||||
public function setAuthorizationServer(AuthorizationServer $server);
|
||||
|
||||
/**
|
||||
* Complete the grant flow
|
||||
* @return array
|
||||
|
||||
@@ -61,6 +61,7 @@ class PasswordGrant extends AbstractGrant
|
||||
/**
|
||||
* Return the callback function
|
||||
* @return callable
|
||||
* @throws
|
||||
*/
|
||||
protected function getVerifyCredentialsCallback()
|
||||
{
|
||||
@@ -74,6 +75,7 @@ class PasswordGrant extends AbstractGrant
|
||||
/**
|
||||
* Complete the password grant
|
||||
* @return array
|
||||
* @throws
|
||||
*/
|
||||
public function completeFlow()
|
||||
{
|
||||
|
||||
@@ -16,7 +16,6 @@ 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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@ 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 Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* OAuth 2.0 Resource Server
|
||||
@@ -38,10 +37,10 @@ class ResourceServer extends AbstractServer
|
||||
|
||||
/**
|
||||
* Initialise the resource server
|
||||
* @param SessionInterface $sessionStorage
|
||||
* @param AccessTokenInteface $accessTokenStorage
|
||||
* @param ClientInterface $clientStorage
|
||||
* @param ScopeInterface $scopeStorage
|
||||
* @param SessionInterface $sessionStorage
|
||||
* @param AccessTokenInterface $accessTokenStorage
|
||||
* @param ClientInterface $clientStorage
|
||||
* @param ScopeInterface $scopeStorage
|
||||
* @return self
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -65,7 +64,7 @@ class ResourceServer extends AbstractServer
|
||||
|
||||
/**
|
||||
* Sets the query string key for the access token.
|
||||
* @param $key The new query string key
|
||||
* @param string $key The new query string key
|
||||
* @return self
|
||||
*/
|
||||
public function setIdKey($key)
|
||||
@@ -86,8 +85,12 @@ class ResourceServer extends AbstractServer
|
||||
|
||||
/**
|
||||
* Checks if the access token is valid or not
|
||||
* @param $headersOnly Limit Access Token to Authorization header only
|
||||
* @param bool $headersOnly Limit Access Token to Authorization header only
|
||||
* @param AccessTokenEntity|null $accessToken Access Token
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws
|
||||
*/
|
||||
public function isValidRequest($headersOnly = true, $accessToken = null)
|
||||
{
|
||||
@@ -114,8 +117,8 @@ class ResourceServer extends AbstractServer
|
||||
|
||||
/**
|
||||
* Reads in the access token from the headers
|
||||
* @param $headersOnly Limit Access Token to Authorization header only
|
||||
* @throws Exception\MissingAccessTokenException Thrown if there is no access token presented
|
||||
* @param bool $headersOnly Limit Access Token to Authorization header only
|
||||
* @throws Exception\InvalidRequestException Thrown if there is no access token presented
|
||||
* @return string
|
||||
*/
|
||||
public function determineAccessToken($headersOnly = false)
|
||||
|
||||
@@ -27,6 +27,7 @@ abstract class AbstractStorage implements StorageInterface
|
||||
/**
|
||||
* Set the server
|
||||
* @param \League\OAuth2\Server\AbstractServer $server
|
||||
* @return self
|
||||
*/
|
||||
public function setServer(AbstractServer $server)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace League\OAuth2\Server\Storage;
|
||||
|
||||
use League\OAuth2\Server\Entity\AbstractTokenEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
|
||||
@@ -29,32 +28,32 @@ interface AccessTokenInterface extends StorageInterface
|
||||
|
||||
/**
|
||||
* Get the scopes for an access token
|
||||
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token
|
||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token
|
||||
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
|
||||
*/
|
||||
public function getScopes(AbstractTokenEntity $token);
|
||||
public function getScopes(AccessTokenEntity $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|integer $sessionId The session ID
|
||||
* @return \League\OAuth2\Server\Entity\AccessToken
|
||||
* @return \League\OAuth2\Server\Entity\AccessTokenEntity
|
||||
*/
|
||||
public function create($token, $expireTime, $sessionId);
|
||||
|
||||
/**
|
||||
* Associate a scope with an acess token
|
||||
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token
|
||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token
|
||||
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
|
||||
* @return void
|
||||
*/
|
||||
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope);
|
||||
public function associateScope(AccessTokenEntity $token, ScopeEntity $scope);
|
||||
|
||||
/**
|
||||
* Delete an access token
|
||||
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token to delete
|
||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete
|
||||
* @return void
|
||||
*/
|
||||
public function delete(AbstractTokenEntity $token);
|
||||
public function delete(AccessTokenEntity $token);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ interface ClientInterface extends StorageInterface
|
||||
* @param string $clientSecret The client's secret (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);
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ interface SessionInterface extends StorageInterface
|
||||
|
||||
/**
|
||||
* Associate a scope with a session
|
||||
* @param \League\OAuth2\Server\Entity\SessionEntity $scope The scope
|
||||
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session
|
||||
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace League\OAuth2\Server\TokenType;
|
||||
|
||||
use League\OAuth2\Server\AbstractServer;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
abstract class AbstractTokenType
|
||||
{
|
||||
@@ -36,8 +35,7 @@ abstract class AbstractTokenType
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* Set the server
|
||||
* @param \League\OAuth2\Server\AbstractServer $server
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setServer(AbstractServer $server)
|
||||
{
|
||||
@@ -47,8 +45,7 @@ abstract class AbstractTokenType
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the session entity
|
||||
* @param \League\OAuth2\Server\Entity\SessionEntity $session
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSession(SessionEntity $session)
|
||||
{
|
||||
@@ -58,9 +55,7 @@ abstract class AbstractTokenType
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a key/value response pair
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setParam($key, $value)
|
||||
{
|
||||
@@ -68,19 +63,10 @@ abstract class AbstractTokenType
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a key from the response array
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParam($key)
|
||||
{
|
||||
return isset($this->response[$key]) ? $this->response[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the access token in the authorization header
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @return string
|
||||
*/
|
||||
abstract public function determineAccessTokenInHeader(Request $request);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
|
||||
namespace League\OAuth2\Server\TokenType;
|
||||
|
||||
use League\OAuth2\Server\AbstractServer;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
interface TokenTypeInterface
|
||||
{
|
||||
/**
|
||||
@@ -18,4 +22,38 @@ interface TokenTypeInterface
|
||||
* @return array
|
||||
*/
|
||||
public function generateResponse();
|
||||
|
||||
/**
|
||||
* Set the server
|
||||
* @param \League\OAuth2\Server\AbstractServer $server
|
||||
* @return self
|
||||
*/
|
||||
public function setServer(AbstractServer $server);
|
||||
|
||||
/**
|
||||
* Set a key/value response pair
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setParam($key, $value);
|
||||
|
||||
/**
|
||||
* Get a key from the response array
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($key);
|
||||
|
||||
/**
|
||||
* @param \League\OAuth2\Server\Entity\SessionEntity $session
|
||||
* @return self
|
||||
*/
|
||||
public function setSession(SessionEntity $session);
|
||||
|
||||
/**
|
||||
* Determine the access token in the authorization header
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @return string
|
||||
*/
|
||||
public function determineAccessTokenInHeader(Request $request);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
||||
$server->requireScopeParam(true);
|
||||
$server->requireStateParam(true);
|
||||
$server->setDefaultScope('foobar');
|
||||
$server->setScopeDelimeter(',');
|
||||
$server->setScopeDelimiter(',');
|
||||
$server->setAccessTokenTTL(1);
|
||||
|
||||
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
|
||||
@@ -36,7 +36,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($server->stateParamRequired());
|
||||
$this->assertTrue($server->getScopeStorage() instanceof ScopeInterface);
|
||||
$this->assertEquals('foobar', $server->getDefaultScope());
|
||||
$this->assertEquals(',', $server->getScopeDelimeter());
|
||||
$this->assertEquals(',', $server->getScopeDelimiter());
|
||||
$this->assertEquals(1, $server->getAccessTokenTTL());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user