mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
Renamed Server to AuthorizationServer
This commit is contained in:
parent
c3a7c418da
commit
f6f39698d9
@ -16,7 +16,7 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
|||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Server implements EmitterAwareInterface
|
class AuthorizationServer implements EmitterAwareInterface
|
||||||
{
|
{
|
||||||
use EmitterAwareTrait;
|
use EmitterAwareTrait;
|
||||||
|
|
@ -3,23 +3,23 @@
|
|||||||
namespace League\OAuth2\Server\Middleware;
|
namespace League\OAuth2\Server\Middleware;
|
||||||
|
|
||||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||||
use League\OAuth2\Server\Server;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class AuthenticationServerMiddleware
|
class AuthorizationServerMiddleware
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \League\OAuth2\Server\Server
|
* @var \League\OAuth2\Server\AuthorizationServer
|
||||||
*/
|
*/
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AuthenticationServerMiddleware constructor.
|
* AuthorizationServerMiddleware constructor.
|
||||||
*
|
*
|
||||||
* @param \League\OAuth2\Server\Server $server
|
* @param \League\OAuth2\Server\AuthorizationServer $server
|
||||||
*/
|
*/
|
||||||
public function __construct(Server $server)
|
public function __construct(AuthorizationServer $server)
|
||||||
{
|
{
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
|||||||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||||
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
|
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
|
||||||
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
|
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
|
||||||
use League\OAuth2\Server\Server;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use LeagueTests\Stubs\AccessTokenEntity;
|
use LeagueTests\Stubs\AccessTokenEntity;
|
||||||
use LeagueTests\Stubs\AuthCodeEntity;
|
use LeagueTests\Stubs\AuthCodeEntity;
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
@ -24,11 +24,11 @@ use Zend\Diactoros\Response;
|
|||||||
use Zend\Diactoros\ServerRequest;
|
use Zend\Diactoros\ServerRequest;
|
||||||
use Zend\Diactoros\ServerRequestFactory;
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
|
|
||||||
class ServerTest extends \PHPUnit_Framework_TestCase
|
class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testRespondToRequestInvalidGrantType()
|
public function testRespondToRequestInvalidGrantType()
|
||||||
{
|
{
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$this->getMock(ClientRepositoryInterface::class),
|
$this->getMock(ClientRepositoryInterface::class),
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
$this->getMock(AccessTokenRepositoryInterface::class),
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
$this->getMock(ScopeRepositoryInterface::class),
|
||||||
@ -58,7 +58,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class);
|
$accessTokenRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class);
|
||||||
$accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
|
$accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
|
||||||
|
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$clientRepository,
|
$clientRepository,
|
||||||
$accessTokenRepositoryMock,
|
$accessTokenRepositoryMock,
|
||||||
$scopeRepositoryMock,
|
$scopeRepositoryMock,
|
||||||
@ -80,7 +80,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
||||||
|
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$clientRepository,
|
$clientRepository,
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
$this->getMock(AccessTokenRepositoryInterface::class),
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
$this->getMock(ScopeRepositoryInterface::class),
|
||||||
@ -95,30 +95,11 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($method->invoke($server) instanceof BearerTokenResponse);
|
$this->assertTrue($method->invoke($server) instanceof BearerTokenResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateAuthenticatedRequest()
|
|
||||||
{
|
|
||||||
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
|
||||||
|
|
||||||
$server = new Server(
|
|
||||||
$clientRepository,
|
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
|
||||||
'file://' . __DIR__ . '/Stubs/private.key',
|
|
||||||
'file://' . __DIR__ . '/Stubs/public.key'
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$server->validateAuthenticatedRequest(ServerRequestFactory::fromGlobals());
|
|
||||||
} catch (OAuthServerException $e) {
|
|
||||||
$this->assertEquals('Missing "Authorization" header', $e->getHint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCompleteAuthorizationRequest()
|
public function testCompleteAuthorizationRequest()
|
||||||
{
|
{
|
||||||
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
||||||
|
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$clientRepository,
|
$clientRepository,
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
$this->getMock(AccessTokenRepositoryInterface::class),
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
$this->getMock(ScopeRepositoryInterface::class),
|
||||||
@ -164,7 +145,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$clientRepositoryMock,
|
$clientRepositoryMock,
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
$this->getMock(AccessTokenRepositoryInterface::class),
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
$this->getMock(ScopeRepositoryInterface::class),
|
||||||
@ -196,7 +177,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidateAuthorizationRequestUnregistered()
|
public function testValidateAuthorizationRequestUnregistered()
|
||||||
{
|
{
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$this->getMock(ClientRepositoryInterface::class),
|
$this->getMock(ClientRepositoryInterface::class),
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
$this->getMock(AccessTokenRepositoryInterface::class),
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
$this->getMock(ScopeRepositoryInterface::class),
|
@ -4,18 +4,18 @@ namespace LeagueTests\Middleware;
|
|||||||
|
|
||||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||||
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
||||||
use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware;
|
use League\OAuth2\Server\Middleware\AuthorizationServerMiddleware;
|
||||||
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||||
use League\OAuth2\Server\Server;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use LeagueTests\Stubs\AccessTokenEntity;
|
use LeagueTests\Stubs\AccessTokenEntity;
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
use LeagueTests\Stubs\StubResponseType;
|
use LeagueTests\Stubs\StubResponseType;
|
||||||
use Zend\Diactoros\Response;
|
use Zend\Diactoros\Response;
|
||||||
use Zend\Diactoros\ServerRequestFactory;
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
|
|
||||||
class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase
|
class AuthorizationServerMiddlewareTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testValidResponse()
|
public function testValidResponse()
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class);
|
$accessRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class);
|
||||||
$accessRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
|
$accessRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
|
||||||
|
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$clientRepository,
|
$clientRepository,
|
||||||
$accessRepositoryMock,
|
$accessRepositoryMock,
|
||||||
$scopeRepositoryMock,
|
$scopeRepositoryMock,
|
||||||
@ -45,7 +45,7 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals();
|
$request = ServerRequestFactory::fromGlobals();
|
||||||
|
|
||||||
$middleware = new AuthenticationServerMiddleware($server);
|
$middleware = new AuthorizationServerMiddleware($server);
|
||||||
$response = $middleware->__invoke(
|
$response = $middleware->__invoke(
|
||||||
$request,
|
$request,
|
||||||
new Response(),
|
new Response(),
|
||||||
@ -61,7 +61,7 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
$clientRepository = $this->getMock(ClientRepositoryInterface::class);
|
||||||
$clientRepository->method('getClientEntity')->willReturn(null);
|
$clientRepository->method('getClientEntity')->willReturn(null);
|
||||||
|
|
||||||
$server = new Server(
|
$server = new AuthorizationServer(
|
||||||
$clientRepository,
|
$clientRepository,
|
||||||
$this->getMock(AccessTokenRepositoryInterface::class),
|
$this->getMock(AccessTokenRepositoryInterface::class),
|
||||||
$this->getMock(ScopeRepositoryInterface::class),
|
$this->getMock(ScopeRepositoryInterface::class),
|
||||||
@ -78,7 +78,7 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals();
|
$request = ServerRequestFactory::fromGlobals();
|
||||||
|
|
||||||
$middleware = new AuthenticationServerMiddleware($server);
|
$middleware = new AuthorizationServerMiddleware($server);
|
||||||
|
|
||||||
$response = $middleware->__invoke(
|
$response = $middleware->__invoke(
|
||||||
$request,
|
$request,
|
Loading…
Reference in New Issue
Block a user