mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-16 10:18:55 +05:30
Updated with new entity names
This commit is contained in:
parent
8fbbc7bd07
commit
97fd115530
@ -24,7 +24,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Access token associated to refresh token
|
* Access token associated to refresh token
|
||||||
* @var \League\OAuth2\Server\Entity\AccessToken
|
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
|
||||||
*/
|
*/
|
||||||
protected $accessToken;
|
protected $accessToken;
|
||||||
|
|
||||||
@ -61,11 +61,6 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
$this->getExpireTime(),
|
$this->getExpireTime(),
|
||||||
$this->getAccessToken()->getToken()
|
$this->getAccessToken()->getToken()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Associate the scope with the token
|
|
||||||
foreach ($this->getScopes() as $scope) {
|
|
||||||
$this->server->getStorage('refresh_token')->associateScope($this->getToken(), $scope->getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,6 +68,6 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
*/
|
*/
|
||||||
public function expire()
|
public function expire()
|
||||||
{
|
{
|
||||||
$this->server->getStorage('refresh_token')->delete($this->getToken());
|
$this->server->getStorage('refresh_token')->delete($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ class SessionEntity
|
|||||||
public function getScopes()
|
public function getScopes()
|
||||||
{
|
{
|
||||||
if ($this->scopes === null) {
|
if ($this->scopes === null) {
|
||||||
$this->scopes = $this->formatScopes($this->server->getStorage('session')->getScopes($this->getId()));
|
$this->scopes = $this->formatScopes($this->server->getStorage('session')->getScopes($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->scopes;
|
return $this->scopes;
|
||||||
@ -263,7 +263,7 @@ class SessionEntity
|
|||||||
|
|
||||||
// Associate the scope with the session
|
// Associate the scope with the session
|
||||||
foreach ($this->getScopes() as $scope) {
|
foreach ($this->getScopes() as $scope) {
|
||||||
$this->server->getStorage('session')->associateScope($this->getId(), $scope->getId());
|
$this->server->getStorage('session')->associateScope($this, $scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,7 +138,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
$this->getIdentifier()
|
$this->getIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (($scope instanceof Scope) === false) {
|
if (($scope instanceof ScopeEntity) === false) {
|
||||||
throw new Exception\InvalidScopeException($scopeItem);
|
throw new Exception\InvalidScopeException($scopeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,14 +150,14 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the local scopes array
|
* Format the local scopes array
|
||||||
* @param array $unformated Array of Array of \League\OAuth2\Server\Entity\Scope
|
* @param array $unformated Array of Array of \League\OAuth2\Server\Entity\ScopeEntity
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function formatScopes($unformated = [])
|
protected function formatScopes($unformated = [])
|
||||||
{
|
{
|
||||||
$scopes = [];
|
$scopes = [];
|
||||||
foreach ($unformated as $scope) {
|
foreach ($unformated as $scope) {
|
||||||
if ($scope instanceof Scope) {
|
if ($scope instanceof ScopeEntity) {
|
||||||
$scopes[$scope->getId()] = $scope;
|
$scopes[$scope->getId()] = $scope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,12 @@ namespace League\OAuth2\Server\Grant;
|
|||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Request;
|
use League\OAuth2\Server\Request;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
use League\OAuth2\Server\Entity\Client;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshToken;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\Session;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\AccessToken;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Entity\AuthCode as AC;
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
use League\OAuth2\Server\Storage\ClientInterface;
|
||||||
@ -100,7 +100,7 @@ class AuthCode extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure response type is one that is recognised
|
// Ensure response type is one that is recognised
|
||||||
if ( ! in_array($responseType, $this->server->getResponseTypes())) {
|
if (!in_array($responseType, $this->server->getResponseTypes())) {
|
||||||
throw new Exception\UnsupportedResponseTypeException($responseType);
|
throw new Exception\UnsupportedResponseTypeException($responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class AuthCode extends AbstractGrant
|
|||||||
$this->getIdentifier()
|
$this->getIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (($client instanceof Client) === false) {
|
if (($client instanceof ClientEntity) === false) {
|
||||||
throw new Exception\InvalidClientException();
|
throw new Exception\InvalidClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,13 +140,13 @@ class AuthCode extends AbstractGrant
|
|||||||
public function newAuthoriseRequest($type, $typeId, $authParams = [])
|
public function newAuthoriseRequest($type, $typeId, $authParams = [])
|
||||||
{
|
{
|
||||||
// Create a new session
|
// Create a new session
|
||||||
$session = new Session($this->server);
|
$session = new SessionEntity($this->server);
|
||||||
$session->setOwner($type, $typeId);
|
$session->setOwner($type, $typeId);
|
||||||
$session->associateClient($authParams['client']);
|
$session->associateClient($authParams['client']);
|
||||||
$session->save();
|
$session->save();
|
||||||
|
|
||||||
// Create a new auth code
|
// Create a new auth code
|
||||||
$authCode = new AC($this->server);
|
$authCode = new AuthCodeEntity($this->server);
|
||||||
$authCode->setToken(SecureKey::generate());
|
$authCode->setToken(SecureKey::generate());
|
||||||
$authCode->setRedirectUri($authParams['redirect_uri']);
|
$authCode->setRedirectUri($authParams['redirect_uri']);
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ class AuthCode extends AbstractGrant
|
|||||||
$this->getIdentifier()
|
$this->getIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (($client instanceof Client) === false) {
|
if (($client instanceof ClientEntity) === false) {
|
||||||
throw new Exception\InvalidClientException();
|
throw new Exception\InvalidClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ class AuthCode extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
$code = $this->server->getStorage('auth_code')->get($authCode);
|
$code = $this->server->getStorage('auth_code')->get($authCode);
|
||||||
if (($code instanceof AC) === false) {
|
if (($code instanceof AuthCodeEntity) === false) {
|
||||||
throw new Exception\InvalidRequestException('code');
|
throw new Exception\InvalidRequestException('code');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ class AuthCode extends AbstractGrant
|
|||||||
$authCodeScopes = $code->getScopes();
|
$authCodeScopes = $code->getScopes();
|
||||||
|
|
||||||
// Generate the access token
|
// Generate the access token
|
||||||
$accessToken = new AccessToken($this->server);
|
$accessToken = new AccessTokenEntity($this->server);
|
||||||
$accessToken->setToken(SecureKey::generate());
|
$accessToken->setToken(SecureKey::generate());
|
||||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ class AuthCode extends AbstractGrant
|
|||||||
|
|
||||||
// Associate a refresh token if set
|
// Associate a refresh token if set
|
||||||
if ($this->server->hasGrantType('refresh_token')) {
|
if ($this->server->hasGrantType('refresh_token')) {
|
||||||
$refreshToken = new RefreshToken($this->server);
|
$refreshToken = new RefreshTokenEntity($this->server);
|
||||||
$refreshToken->setToken(SecureKey::generate());
|
$refreshToken->setToken(SecureKey::generate());
|
||||||
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
||||||
$response['refresh_token'] = $refreshToken->getToken();
|
$response['refresh_token'] = $refreshToken->getToken();
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Entity\AccessToken;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\Client;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\Session;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
@ -77,7 +77,7 @@ class ClientCredentials extends AbstractGrant
|
|||||||
$this->getIdentifier()
|
$this->getIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (($client instanceof Client) === false) {
|
if (($client instanceof ClientEntity) === false) {
|
||||||
throw new Exception\InvalidClientException();
|
throw new Exception\InvalidClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +86,12 @@ class ClientCredentials extends AbstractGrant
|
|||||||
$scopes = $this->validateScopes($scopeParam);
|
$scopes = $this->validateScopes($scopeParam);
|
||||||
|
|
||||||
// Create a new session
|
// Create a new session
|
||||||
$session = new Session($this->server);
|
$session = new SessionEntity($this->server);
|
||||||
$session->setOwner('client', $client->getId());
|
$session->setOwner('client', $client->getId());
|
||||||
$session->associateClient($client);
|
$session->associateClient($client);
|
||||||
|
|
||||||
// Generate an access token
|
// Generate an access token
|
||||||
$accessToken = new AccessToken($this->server);
|
$accessToken = new AccessTokenEntity($this->server);
|
||||||
$accessToken->setToken(SecureKey::generate());
|
$accessToken->setToken(SecureKey::generate());
|
||||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Entity\AccessToken;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\Client;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\Session;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
@ -101,7 +101,7 @@ class Password extends AbstractGrant
|
|||||||
$this->getIdentifier()
|
$this->getIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (($client instanceof Client) === false) {
|
if (($client instanceof ClientEntity) === false) {
|
||||||
throw new Exception\InvalidClientException();
|
throw new Exception\InvalidClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,12 +127,12 @@ class Password extends AbstractGrant
|
|||||||
$scopes = $this->validateScopes($scopeParam);
|
$scopes = $this->validateScopes($scopeParam);
|
||||||
|
|
||||||
// Create a new session
|
// Create a new session
|
||||||
$session = new Session($this->server);
|
$session = new SessionEntity($this->server);
|
||||||
$session->setOwner('user', $userId);
|
$session->setOwner('user', $userId);
|
||||||
$session->associateClient($client);
|
$session->associateClient($client);
|
||||||
|
|
||||||
// Generate an access token
|
// Generate an access token
|
||||||
$accessToken = new AccessToken($this->server);
|
$accessToken = new AccessTokenEntity($this->server);
|
||||||
$accessToken->setToken(SecureKey::generate());
|
$accessToken->setToken(SecureKey::generate());
|
||||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ class Password extends AbstractGrant
|
|||||||
|
|
||||||
// Associate a refresh token if set
|
// Associate a refresh token if set
|
||||||
if ($this->server->hasGrantType('refresh_token')) {
|
if ($this->server->hasGrantType('refresh_token')) {
|
||||||
$refreshToken = new RT($this->server);
|
$refreshToken = new RefreshTokenEntity($this->server);
|
||||||
$refreshToken->setToken(SecureKey::generate());
|
$refreshToken->setToken(SecureKey::generate());
|
||||||
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
||||||
$response['refresh_token'] = $refreshToken->getToken();
|
$response['refresh_token'] = $refreshToken->getToken();
|
||||||
|
@ -18,9 +18,10 @@ use League\OAuth2\Server\Util\SecureKey;
|
|||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
use League\OAuth2\Server\Storage\ClientInterface;
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\AccessToken;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\Session;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Referesh token grant
|
* Referesh token grant
|
||||||
@ -80,7 +81,7 @@ class RefreshToken extends AbstractGrant
|
|||||||
$this->getIdentifier()
|
$this->getIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($client === null) {
|
if (($client instanceof ClientEntity) === false) {
|
||||||
throw new Exception\InvalidClientException();
|
throw new Exception\InvalidClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ class RefreshToken extends AbstractGrant
|
|||||||
// Validate refresh token
|
// Validate refresh token
|
||||||
$oldRefreshToken = $this->server->getStorage('refresh_token')->get($oldRefreshTokenParam);
|
$oldRefreshToken = $this->server->getStorage('refresh_token')->get($oldRefreshTokenParam);
|
||||||
|
|
||||||
if (($oldRefreshToken instanceof RT) === false) {
|
if (($oldRefreshToken instanceof RefreshTokenEntity) === false) {
|
||||||
throw new Exception\InvalidRefreshException();
|
throw new Exception\InvalidRefreshException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ class RefreshToken extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a new access token and assign it the correct sessions
|
// Generate a new access token and assign it the correct sessions
|
||||||
$newAccessToken = new AccessToken($this->server);
|
$newAccessToken = new AccessTokenEntity($this->server);
|
||||||
$newAccessToken->setToken(SecureKey::generate());
|
$newAccessToken->setToken(SecureKey::generate());
|
||||||
$newAccessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$newAccessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||||
$newAccessToken->setSession($session);
|
$newAccessToken->setSession($session);
|
||||||
@ -146,7 +147,7 @@ class RefreshToken extends AbstractGrant
|
|||||||
$oldRefreshToken->expire($this->server->getStorage('refresh_token'));
|
$oldRefreshToken->expire($this->server->getStorage('refresh_token'));
|
||||||
|
|
||||||
// Generate a new refresh token
|
// Generate a new refresh token
|
||||||
$newRefreshToken = new RT($this->server);
|
$newRefreshToken = new RefreshTokenEntity($this->server);
|
||||||
$newRefreshToken->setToken(SecureKey::generate());
|
$newRefreshToken->setToken(SecureKey::generate());
|
||||||
$newRefreshToken->setExpireTime($this->getRefreshTokenTTL() + time());
|
$newRefreshToken->setExpireTime($this->getRefreshTokenTTL() + time());
|
||||||
$newRefreshToken->setAccessToken($newAccessToken);
|
$newRefreshToken->setAccessToken($newAccessToken);
|
||||||
|
@ -17,7 +17,7 @@ use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|||||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
use League\OAuth2\Server\Entity\AccessToken;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,24 +135,6 @@ class ResourceServer extends AbstractServer
|
|||||||
return $this->accessToken->getSession()->getClient()->getId();
|
return $this->accessToken->getSession()->getClient()->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the access token is valid or not
|
|
||||||
* @param $headersOnly Limit Access Token to Authorization header only
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValidRequest($headersOnly = true, $accessToken = null)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$accessTokenString = ($accessToken !== null) ? $accessToken : $this->determineAccessToken($headersOnly, $accessToken);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the access token
|
|
||||||
$this->accessToken = $this->storages['access_token']->get($accessTokenString);
|
|
||||||
return ($this->accessToken instanceof AccessToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the session scopes
|
* Get the session scopes
|
||||||
* @return array
|
* @return array
|
||||||
@ -183,6 +165,20 @@ class ResourceServer extends AbstractServer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the access token is valid or not
|
||||||
|
* @param $headersOnly Limit Access Token to Authorization header only
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isValidRequest($headersOnly = true, $accessToken = null)
|
||||||
|
{
|
||||||
|
$accessTokenString = ($accessToken !== null) ? $accessToken : $this->determineAccessToken($headersOnly, $accessToken);
|
||||||
|
|
||||||
|
// Set the access token
|
||||||
|
$this->accessToken = $this->storages['access_token']->get($accessTokenString);
|
||||||
|
return ($this->accessToken instanceof AccessTokenEntity);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads in the access token from the headers
|
* Reads in the access token from the headers
|
||||||
* @param $headersOnly Limit Access Token to Authorization header only
|
* @param $headersOnly Limit Access Token to Authorization header only
|
||||||
@ -195,7 +191,9 @@ class ResourceServer extends AbstractServer
|
|||||||
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
|
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
|
||||||
$accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
|
$accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
|
||||||
} elseif ($headersOnly === false) {
|
} elseif ($headersOnly === false) {
|
||||||
$accessToken = $this->getRequest()->request->get($this->tokenKey);
|
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET') ?
|
||||||
|
$this->getRequest()->query->get($this->tokenKey) :
|
||||||
|
$this->getRequest()->request->get($this->tokenKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($accessToken)) {
|
if (empty($accessToken)) {
|
||||||
|
@ -10,7 +10,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
$client = new Client($server);
|
$client = new ClientEntity($server);
|
||||||
$client->setId('foobar');
|
$client->setId('foobar');
|
||||||
$client->setSecret('barfoo');
|
$client->setSecret('barfoo');
|
||||||
$client->setName('Test Client');
|
$client->setName('Test Client');
|
||||||
|
@ -14,58 +14,69 @@ class RefreshTokenTests extends \PHPUnit_Framework_TestCase
|
|||||||
function testSetAccessToken()
|
function testSetAccessToken()
|
||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
$entity = new RefreshToken($server);
|
$entity = new RefreshTokenEntity($server);
|
||||||
$entity->setAccessToken((new AccessToken($server)));
|
$entity->setAccessToken((new AccessTokenEntity($server)));
|
||||||
|
|
||||||
$reflector = new \ReflectionClass($entity);
|
$reflector = new \ReflectionClass($entity);
|
||||||
$accessTokenProperty = $reflector->getProperty('accessToken');
|
$accessTokenProperty = $reflector->getProperty('accessToken');
|
||||||
$accessTokenProperty->setAccessible(true);
|
$accessTokenProperty->setAccessible(true);
|
||||||
|
|
||||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
|
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSave()
|
function testSave()
|
||||||
{
|
{
|
||||||
$server = new Authorization();
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
|
$server->shouldReceive('setAccessTokenStorage');
|
||||||
|
$server->shouldReceive('setRefreshTokenStorage');
|
||||||
|
|
||||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||||
$refreshTokenStorage->shouldReceive('create');
|
$refreshTokenStorage->shouldReceive('create');
|
||||||
$refreshTokenStorage->shouldReceive('setServer');
|
$refreshTokenStorage->shouldReceive('setServer');
|
||||||
$refreshTokenStorage->shouldReceive('associateScope');
|
$refreshTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||||
(new AccessToken($server))->setToken('foobar')
|
(new AccessTokenEntity($server))->setToken('foobar')
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
(new Session($server))
|
(new SessionEntity($server))
|
||||||
);
|
);
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||||
|
|
||||||
$server->setAccessTokenStorage($accessTokenStorage);
|
$server->setAccessTokenStorage($accessTokenStorage);
|
||||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||||
|
|
||||||
$entity = new RefreshToken($server);
|
$entity = new RefreshTokenEntity($server);
|
||||||
$this->assertSame(null, $entity->save());
|
$this->assertSame(null, $entity->save());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testExpire()
|
function testExpire()
|
||||||
{
|
{
|
||||||
$server = new Authorization();
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
|
$server->shouldReceive('setRefreshTokenStorage');
|
||||||
|
|
||||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||||
$refreshTokenStorage->shouldReceive('delete');
|
$refreshTokenStorage->shouldReceive('delete');
|
||||||
$refreshTokenStorage->shouldReceive('setServer');
|
$refreshTokenStorage->shouldReceive('setServer');
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||||
|
|
||||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||||
|
|
||||||
$entity = new RefreshToken($server);
|
$entity = new RefreshTokenEntity($server);
|
||||||
$this->assertSame($entity->expire(), null);
|
$this->assertSame($entity->expire(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class ScopeTests extends \PHPUnit_Framework_TestCase
|
|||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
$scope = new Scope($server);
|
$scope = new ScopeEntity($server);
|
||||||
$scope->setId('foobar');
|
$scope->setId('foobar');
|
||||||
$scope->setDescription('barfoo');
|
$scope->setDescription('barfoo');
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use League\OAuth2\Server\Entity\ClientEntity;
|
|||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use \Mockery as M;
|
use \Mockery as M;
|
||||||
|
|
||||||
class SessionTests extends \PHPUnit_Framework_TestCase
|
class SessionTests extends \PHPUnit_Framework_TestCase
|
||||||
@ -16,19 +16,19 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
|||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
$entity = new Session($server);
|
$entity = new SessionEntity($server);
|
||||||
$entity->setId('foobar');
|
$entity->setId('foobar');
|
||||||
$entity->setOwner('user', 123);
|
$entity->setOwner('user', 123);
|
||||||
$entity->associateAccessToken((new AccessToken($server)));
|
$entity->associateAccessToken((new AccessTokenEntity($server)));
|
||||||
$entity->associateRefreshToken((new RefreshToken($server)));
|
$entity->associateRefreshToken((new RefreshTokenEntity($server)));
|
||||||
$entity->associateClient((new Client($server)));
|
$entity->associateClient((new ClientEntity($server)));
|
||||||
$entity->associateScope((new Scope($server))->setId('foo'));
|
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||||
// $entity->associateAuthCode((new AuthCode($server)));
|
// $entity->associateAuthCode((new AuthCode($server)));
|
||||||
|
|
||||||
$this->assertEquals('foobar', $entity->getId());
|
$this->assertEquals('foobar', $entity->getId());
|
||||||
$this->assertEquals('user', $entity->getOwnerType());
|
$this->assertEquals('user', $entity->getOwnerType());
|
||||||
$this->assertEquals(123, $entity->getOwnerId());
|
$this->assertEquals(123, $entity->getOwnerId());
|
||||||
$this->assertTrue($entity->getClient() instanceof Client);
|
$this->assertTrue($entity->getClient() instanceof ClientEntity);
|
||||||
$this->assertTrue($entity->hasScope('foo'));
|
$this->assertTrue($entity->hasScope('foo'));
|
||||||
|
|
||||||
$reflector = new \ReflectionClass($entity);
|
$reflector = new \ReflectionClass($entity);
|
||||||
@ -37,8 +37,8 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
|||||||
$refreshTokenProperty = $reflector->getProperty('refreshToken');
|
$refreshTokenProperty = $reflector->getProperty('refreshToken');
|
||||||
$refreshTokenProperty->setAccessible(true);
|
$refreshTokenProperty->setAccessible(true);
|
||||||
|
|
||||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
|
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||||
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshToken);
|
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshTokenEntity);
|
||||||
// $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode);
|
// $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,32 +46,36 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
|
|
||||||
$entity = new Session($server);
|
$entity = new SessionEntity($server);
|
||||||
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\Session');
|
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\SessionEntity');
|
||||||
$method = $reflectedEntity->getMethod('formatScopes');
|
$method = $reflectedEntity->getMethod('formatScopes');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$scopes = [
|
$scopes = [
|
||||||
(new Scope($server))->setId('scope1')->setDescription('foo'),
|
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||||
(new Scope($server))->setId('scope2')->setDescription('bar')
|
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $method->invokeArgs($entity, [$scopes]);
|
$result = $method->invokeArgs($entity, [$scopes]);
|
||||||
|
|
||||||
$this->assertTrue(isset($result['scope1']));
|
$this->assertTrue(isset($result['scope1']));
|
||||||
$this->assertTrue(isset($result['scope2']));
|
$this->assertTrue(isset($result['scope2']));
|
||||||
$this->assertTrue($result['scope1'] instanceof Scope);
|
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||||
$this->assertTrue($result['scope2'] instanceof Scope);
|
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetScopes()
|
public function testGetScopes()
|
||||||
{
|
{
|
||||||
$server = new Authorization();
|
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||||
|
$server->shouldReceive('setAccessTokenStorage');
|
||||||
|
$server->shouldReceive('setSessionStorage');
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$server->setAccessTokenStorage($accessTokenStorage);
|
$server->setAccessTokenStorage($accessTokenStorage);
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||||
[]
|
[]
|
||||||
@ -79,18 +83,24 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$server->setSessionStorage($sessionStorage);
|
$server->setSessionStorage($sessionStorage);
|
||||||
|
|
||||||
$entity = new Session($server);
|
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||||
|
|
||||||
|
$entity = new SessionEntity($server);
|
||||||
$this->assertEquals($entity->getScopes(), []);
|
$this->assertEquals($entity->getScopes(), []);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasScopes()
|
public function testHasScopes()
|
||||||
{
|
{
|
||||||
$server = new Authorization();
|
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||||
|
$server->shouldReceive('setAccessTokenStorage');
|
||||||
|
$server->shouldReceive('setSessionStorage');
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$server->setAccessTokenStorage($accessTokenStorage);
|
$server->setAccessTokenStorage($accessTokenStorage);
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||||
[]
|
[]
|
||||||
@ -98,32 +108,40 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$server->setSessionStorage($sessionStorage);
|
$server->setSessionStorage($sessionStorage);
|
||||||
|
|
||||||
$entity = new Session($server);
|
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||||
|
|
||||||
|
$entity = new SessionEntity($server);
|
||||||
$this->assertFalse($entity->hasScope('foo'));
|
$this->assertFalse($entity->hasScope('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSave()
|
function testSave()
|
||||||
{
|
{
|
||||||
$server = new Authorization();
|
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||||
|
$server->shouldReceive('setSessionStorage');
|
||||||
|
$server->shouldReceive('setClientStorage');
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('create');
|
$sessionStorage->shouldReceive('create');
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||||
(new Client($server))->setId('foo')
|
(new ClientEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
|
|
||||||
|
$server->shouldReceive('getStorage')->with('client')->andReturn($clientStorage);
|
||||||
|
|
||||||
$server->setSessionStorage($sessionStorage);
|
$server->setSessionStorage($sessionStorage);
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
|
||||||
$entity = new Session($server);
|
$entity = new SessionEntity($server);
|
||||||
$this->assertEquals(null, $entity->save());
|
$this->assertEquals(null, $entity->save());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,16 +36,16 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$scopes = [
|
$scopes = [
|
||||||
(new Scope($server))->setId('scope1')->setDescription('foo'),
|
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||||
(new Scope($server))->setId('scope2')->setDescription('bar')
|
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $method->invokeArgs($grant, [$scopes]);
|
$result = $method->invokeArgs($grant, [$scopes]);
|
||||||
|
|
||||||
$this->assertTrue(isset($result['scope1']));
|
$this->assertTrue(isset($result['scope1']));
|
||||||
$this->assertTrue(isset($result['scope2']));
|
$this->assertTrue(isset($result['scope2']));
|
||||||
$this->assertTrue($result['scope1'] instanceof Scope);
|
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||||
$this->assertTrue($result['scope2'] instanceof Scope);
|
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateScopes()
|
public function testValidateScopes()
|
||||||
@ -55,7 +55,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
@ -65,7 +65,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
[
|
[
|
||||||
'foo' => (new Scope($server))->setId('foo')
|
'foo' => (new ScopeEntity($server))->setId('foo')
|
||||||
],
|
],
|
||||||
|
|
||||||
$grant->validateScopes('foo')
|
$grant->validateScopes('foo')
|
||||||
@ -113,7 +113,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ use League\OAuth2\Server\Grant\RefreshToken;
|
|||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\AuthCode as AC;
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Exception\InvalidRequestException;
|
use League\OAuth2\Server\Exception\InvalidRequestException;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [];
|
$_POST = [];
|
||||||
|
$server = new AuthorizationServer;
|
||||||
|
|
||||||
$server = new Authorization;
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -43,11 +43,11 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
|
$server = new AuthorizationServer;
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -62,10 +62,10 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar'
|
||||||
];
|
];
|
||||||
|
$server = new AuthorizationServer;
|
||||||
|
|
||||||
$server = new Authorization;
|
|
||||||
$server->requireStateParam(true);
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
$server->requireStateParam(true);
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$grant->checkAuthoriseParams();
|
$grant->checkAuthoriseParams();
|
||||||
@ -79,8 +79,8 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar'
|
||||||
];
|
];
|
||||||
|
$server = new AuthorizationServer;
|
||||||
|
|
||||||
$server = new Authorization;
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -96,8 +96,8 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'response_type' => 'foobar'
|
'response_type' => 'foobar'
|
||||||
];
|
];
|
||||||
|
$server = new AuthorizationServer;
|
||||||
|
|
||||||
$server = new Authorization;
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -113,14 +113,15 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'response_type' => 'code'
|
'response_type' => 'code'
|
||||||
];
|
];
|
||||||
|
$server = new AuthorizationServer;
|
||||||
|
|
||||||
$server = new Authorization;
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(null);
|
$clientStorage->shouldReceive('get')->andReturn(null);
|
||||||
|
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -138,13 +139,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'scope' => 'foo'
|
'scope' => 'foo'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -179,20 +180,20 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'scope' => 'foo'
|
'scope' => 'foo'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -200,14 +201,14 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -219,19 +220,19 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$result = $grant->checkAuthoriseParams();
|
$result = $grant->checkAuthoriseParams();
|
||||||
|
|
||||||
$this->assertTrue($result['client'] instanceof Client);
|
$this->assertTrue($result['client'] instanceof ClientEntity);
|
||||||
$this->assertTrue($result['redirect_uri'] === $_POST['redirect_uri']);
|
$this->assertTrue($result['redirect_uri'] === $_POST['redirect_uri']);
|
||||||
$this->assertTrue($result['state'] === null);
|
$this->assertTrue($result['state'] === null);
|
||||||
$this->assertTrue($result['response_type'] === 'code');
|
$this->assertTrue($result['response_type'] === 'code');
|
||||||
$this->assertTrue($result['scopes']['foo'] instanceof Scope);
|
$this->assertTrue($result['scopes']['foo'] instanceof ScopeEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNewAuthoriseRequest()
|
public function testNewAuthoriseRequest()
|
||||||
{
|
{
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
|
|
||||||
$client = (new Client($server))->setId('testapp');
|
$client = (new ClientEntity($server))->setId('testapp');
|
||||||
$scope = (new Scope($server))->setId('foo');
|
$scope = (new ScopeEntity($server))->setId('foo');
|
||||||
|
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -264,7 +265,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'authorization_code';
|
$_POST['grant_type'] = 'authorization_code';
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -281,7 +282,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -298,7 +299,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -316,7 +317,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
@ -340,13 +341,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -389,13 +390,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'code' => 'foobar'
|
'code' => 'foobar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -438,13 +439,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'code' => 'foobar'
|
'code' => 'foobar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -464,7 +465,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||||
$authCodeStorage->shouldReceive('setServer');
|
$authCodeStorage->shouldReceive('setServer');
|
||||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||||
(new AC($server))->setToken('foobar')->setRedirectUri('http://fail/face')
|
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://fail/face')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -487,16 +488,16 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'code' => 'foo'
|
'code' => 'foo'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -504,7 +505,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
||||||
(new Session($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
@ -512,23 +513,23 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||||
$authCodeStorage->shouldReceive('setServer');
|
$authCodeStorage->shouldReceive('setServer');
|
||||||
$authCodeStorage->shouldReceive('delete');
|
$authCodeStorage->shouldReceive('delete');
|
||||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||||
(new AC($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
||||||
);
|
);
|
||||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -551,17 +552,17 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'code' => 'foo'
|
'code' => 'foo'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new AuthCode;
|
$grant = new AuthCode;
|
||||||
$rtgrant = new RefreshToken;
|
$rtgrant = new RefreshToken;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -569,7 +570,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
||||||
(new Session($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
@ -577,23 +578,23 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||||
$authCodeStorage->shouldReceive('setServer');
|
$authCodeStorage->shouldReceive('setServer');
|
||||||
$authCodeStorage->shouldReceive('delete');
|
$authCodeStorage->shouldReceive('delete');
|
||||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||||
(new AC($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
||||||
);
|
);
|
||||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||||
|
@ -5,7 +5,7 @@ namespace LeagueTests\Grant;
|
|||||||
use League\OAuth2\Server\Grant\ClientCredentials;
|
use League\OAuth2\Server\Grant\ClientCredentials;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Grant\ClientException;
|
use League\OAuth2\Server\Grant\ClientException;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'client_credentials';
|
$_POST['grant_type'] = 'client_credentials';
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new ClientCredentials;
|
$grant = new ClientCredentials;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -34,7 +34,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new ClientCredentials;
|
$grant = new ClientCredentials;
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@ -51,7 +51,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new ClientCredentials;
|
$grant = new ClientCredentials;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
@ -75,13 +75,13 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'scope' => 'foo'
|
'scope' => 'foo'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new ClientCredentials;
|
$grant = new ClientCredentials;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -115,13 +115,13 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new ClientCredentials;
|
$grant = new ClientCredentials;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -139,7 +139,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
// $scopeStorage->shouldReceive('get')->andReturn(
|
// $scopeStorage->shouldReceive('get')->andReturn(
|
||||||
// // (new Scope($server))->setId('foo')
|
// // (new ScopeEntity($server))->setId('foo')
|
||||||
// );
|
// );
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -160,20 +160,20 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'scope' => 'foo'
|
'scope' => 'foo'
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new Authorization;
|
$server = new AuthorizationServer;
|
||||||
$grant = new ClientCredentials;
|
$grant = new ClientCredentials;
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -181,14 +181,14 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
@ -5,6 +5,8 @@ namespace LeagueTests\Grant;
|
|||||||
use League\OAuth2\Server\Grant\Password;
|
use League\OAuth2\Server\Grant\Password;
|
||||||
use League\OAuth2\Server\Grant\RefreshToken;
|
use League\OAuth2\Server\Grant\RefreshToken;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
@ -80,7 +82,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -123,7 +125,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -167,7 +169,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -212,7 +214,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -259,7 +261,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -309,14 +311,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -324,14 +326,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -363,14 +365,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -378,14 +380,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -422,14 +424,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -437,14 +439,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||||
|
@ -7,7 +7,7 @@ use League\OAuth2\Server\Entity\ScopeEntity;
|
|||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -127,7 +127,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||||
@ -161,7 +161,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -169,18 +169,18 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([]);
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
(new Session($server))
|
(new SessionEntity($server))
|
||||||
);
|
);
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||||
(new AccessToken($server))
|
(new AccessTokenEntity($server))
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('delete');
|
$accessTokenStorage->shouldReceive('delete');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -190,13 +190,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$refreshTokenStorage->shouldReceive('delete');
|
$refreshTokenStorage->shouldReceive('delete');
|
||||||
$refreshTokenStorage->shouldReceive('create');
|
$refreshTokenStorage->shouldReceive('create');
|
||||||
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
||||||
(new RT($server))
|
(new RefreshTokenEntity($server))
|
||||||
);
|
);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -228,12 +228,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer;
|
||||||
$grant = new RefreshToken;
|
$grant = new RefreshToken;
|
||||||
|
|
||||||
$oldSession = (new Session($server))->associateScope((new Scope($server))->setId('foo'));
|
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -247,12 +247,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||||
(new AccessToken($server))
|
(new AccessTokenEntity($server))
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('delete');
|
$accessTokenStorage->shouldReceive('delete');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -262,13 +262,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$refreshTokenStorage->shouldReceive('delete');
|
$refreshTokenStorage->shouldReceive('delete');
|
||||||
$refreshTokenStorage->shouldReceive('create');
|
$refreshTokenStorage->shouldReceive('create');
|
||||||
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
||||||
(new RT($server))
|
(new RefreshTokenEntity($server))
|
||||||
);
|
);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@ -300,12 +300,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer;
|
||||||
$grant = new RefreshToken;
|
$grant = new RefreshToken;
|
||||||
|
|
||||||
$oldSession = (new Session($server))->associateScope((new Scope($server))->setId('foo'));
|
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andReturn(
|
$clientStorage->shouldReceive('get')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -319,12 +319,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||||
(new AccessToken($server))
|
(new AccessTokenEntity($server))
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('delete');
|
$accessTokenStorage->shouldReceive('delete');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo')
|
(new ScopeEntity($server))->setId('foo')
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@ -334,13 +334,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$refreshTokenStorage->shouldReceive('delete');
|
$refreshTokenStorage->shouldReceive('delete');
|
||||||
$refreshTokenStorage->shouldReceive('create');
|
$refreshTokenStorage->shouldReceive('create');
|
||||||
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
||||||
(new RT($server))
|
(new RefreshTokenEntity($server))
|
||||||
);
|
);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
(new Scope($server))->setId('blah')
|
(new ScopeEntity($server))->setId('blah')
|
||||||
);
|
);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
@ -139,20 +139,20 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$server->setTokenKey('at');
|
$server->setTokenKey('at');
|
||||||
|
|
||||||
$accessTokenStorage->shouldReceive('get')->andReturn(
|
$accessTokenStorage->shouldReceive('get')->andReturn(
|
||||||
(new AccessToken($server))->setToken('abcdef')
|
(new AccessTokenEntity($server))->setToken('abcdef')
|
||||||
);
|
);
|
||||||
|
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new Scope($server))->setId('foo'),
|
(new ScopeEntity($server))->setId('foo'),
|
||||||
(new Scope($server))->setId('bar')
|
(new ScopeEntity($server))->setId('bar')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
(new Session($server))->setId('foobar')->setOwner('user', 123)
|
(new SessionEntity($server))->setId('foobar')->setOwner('user', 123)
|
||||||
);
|
);
|
||||||
|
|
||||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||||
(new Client($server))->setId('testapp')
|
(new ClientEntity($server))->setId('testapp')
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||||
|
Loading…
Reference in New Issue
Block a user