Skip to content

Commit

Permalink
feature #15 use http-foundation instead of PSR-7 (azjezz)
Browse files Browse the repository at this point in the history
This PR was merged into the 0.1-dev branch.

Discussion
----------

use http-foundation instead of PSR-7

closes #14

Commits
-------

2a7c34f use http-foundation instead of PSR-7
  • Loading branch information
chalasr committed Apr 19, 2021
2 parents 93c4078 + 2a7c34f commit 9f9edd0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
8 changes: 2 additions & 6 deletions src/Controller/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -106,11 +105,8 @@ public function indexAction(Request $request): Response

$authRequest->setUser($this->userConverter->toLeague($event->getUser()));

if ($event->hasResponse()) {
/** @var ResponseInterface $response */
$response = $event->getResponse();

return $this->httpFoundationFactory->createResponse($response);
if ($response = $event->getResponse()) {
return $response;
}

$authRequest->setAuthorizationApproved($event->getAuthorizationResolution());
Expand Down
13 changes: 4 additions & 9 deletions src/Event/AuthorizationRequestResolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use League\Bundle\OAuth2ServerBundle\Model\Client;
use League\Bundle\OAuth2ServerBundle\Model\Scope;
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Contracts\EventDispatcher\Event;

Expand Down Expand Up @@ -37,7 +37,7 @@ final class AuthorizationRequestResolveEvent extends Event
private $authorizationResolution = self::AUTHORIZATION_DENIED;

/**
* @var ResponseInterface|null
* @var Response|null
*/
private $response;

Expand Down Expand Up @@ -70,20 +70,15 @@ public function resolveAuthorization(bool $authorizationResolution): self
return $this;
}

public function hasResponse(): bool
{
return $this->response instanceof ResponseInterface;
}

/**
* @psalm-mutation-free
*/
public function getResponse(): ?ResponseInterface
public function getResponse(): ?Response
{
return $this->response;
}

public function setResponse(ResponseInterface $response): self
public function setResponse(Response $response): self
{
$this->response = $response;
$this->stopPropagation();
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
$routes
->add('oauth2_authorize', '/authorize')
->controller([AuthorizationController::class, 'indexAction'])
->methods(['GET'])

->add('oauth2_token', '/token')
->controller([TokenController::class, 'indexAction'])
Expand Down
19 changes: 12 additions & 7 deletions tests/Acceptance/AuthorizationEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
use League\Bundle\OAuth2ServerBundle\Tests\Fixtures\FixtureFactory;
use League\Bundle\OAuth2ServerBundle\Tests\TestHelper;
use Nyholm\Psr7\Response;
use Symfony\Component\HttpFoundation\Response;

final class AuthorizationEndpointTest extends AbstractAcceptanceTest
{
Expand Down Expand Up @@ -303,8 +303,9 @@ public function testCodeRequestRedirectToResolutionUri(): void
->getContainer()
->get('event_dispatcher')
->addListener(OAuth2Events::AUTHORIZATION_REQUEST_RESOLVE, static function (AuthorizationRequestResolveEvent $event): void {
$response = (new Response())->withStatus(302)->withHeader('Location', '/authorize/consent');
$event->setResponse($response);
$event->setResponse(new Response(null, 302, [
'Location' => '/authorize/consent',
]));
});

$this->client->request(
Expand Down Expand Up @@ -335,8 +336,9 @@ public function testAuthorizationRequestEventIsStoppedAfterSettingAResponse(): v
$event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_APPROVED);
}, 100);
$eventDispatcher->addListener(OAuth2Events::AUTHORIZATION_REQUEST_RESOLVE, static function (AuthorizationRequestResolveEvent $event): void {
$response = (new Response())->withStatus(302)->withHeader('Location', '/authorize/consent');
$event->setResponse($response);
$event->setResponse(new Response(null, 302, [
'Location' => '/authorize/consent',
]));
}, 200);

$this->client->request(
Expand Down Expand Up @@ -365,8 +367,11 @@ public function testAuthorizationRequestEventIsStoppedAfterResolution(): void
$event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_APPROVED);
}, 200);
$eventDispatcher->addListener(OAuth2Events::AUTHORIZATION_REQUEST_RESOLVE, static function (AuthorizationRequestResolveEvent $event): void {
$response = (new Response())->withStatus(302)->withHeader('Location', '/authorize/consent');
$event->setResponse($response);
$event->setResponse(
new Response(null, 302, [
'Location' => '/authorize/consent',
])
);
}, 100);

$this->client->request(
Expand Down

0 comments on commit 9f9edd0

Please sign in to comment.