Skip to content

Commit 9f9edd0

Browse files
committed
feature #15 use http-foundation instead of PSR-7 (azjezz)
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
2 parents 93c4078 + 2a7c34f commit 9f9edd0

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

src/Controller/AuthorizationController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use League\OAuth2\Server\AuthorizationServer;
1414
use League\OAuth2\Server\Exception\OAuthServerException;
1515
use Psr\Http\Message\ResponseFactoryInterface;
16-
use Psr\Http\Message\ResponseInterface;
1716
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
1817
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1918
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -106,11 +105,8 @@ public function indexAction(Request $request): Response
106105

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

109-
if ($event->hasResponse()) {
110-
/** @var ResponseInterface $response */
111-
$response = $event->getResponse();
112-
113-
return $this->httpFoundationFactory->createResponse($response);
108+
if ($response = $event->getResponse()) {
109+
return $response;
114110
}
115111

116112
$authRequest->setAuthorizationApproved($event->getAuthorizationResolution());

src/Event/AuthorizationRequestResolveEvent.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use League\Bundle\OAuth2ServerBundle\Model\Client;
88
use League\Bundle\OAuth2ServerBundle\Model\Scope;
99
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
10-
use Psr\Http\Message\ResponseInterface;
10+
use Symfony\Component\HttpFoundation\Response;
1111
use Symfony\Component\Security\Core\User\UserInterface;
1212
use Symfony\Contracts\EventDispatcher\Event;
1313

@@ -37,7 +37,7 @@ final class AuthorizationRequestResolveEvent extends Event
3737
private $authorizationResolution = self::AUTHORIZATION_DENIED;
3838

3939
/**
40-
* @var ResponseInterface|null
40+
* @var Response|null
4141
*/
4242
private $response;
4343

@@ -70,20 +70,15 @@ public function resolveAuthorization(bool $authorizationResolution): self
7070
return $this;
7171
}
7272

73-
public function hasResponse(): bool
74-
{
75-
return $this->response instanceof ResponseInterface;
76-
}
77-
7873
/**
7974
* @psalm-mutation-free
8075
*/
81-
public function getResponse(): ?ResponseInterface
76+
public function getResponse(): ?Response
8277
{
8378
return $this->response;
8479
}
8580

86-
public function setResponse(ResponseInterface $response): self
81+
public function setResponse(Response $response): self
8782
{
8883
$this->response = $response;
8984
$this->stopPropagation();

src/Resources/config/routes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
$routes
1111
->add('oauth2_authorize', '/authorize')
1212
->controller([AuthorizationController::class, 'indexAction'])
13-
->methods(['GET'])
1413

1514
->add('oauth2_token', '/token')
1615
->controller([TokenController::class, 'indexAction'])

tests/Acceptance/AuthorizationEndpointTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
1515
use League\Bundle\OAuth2ServerBundle\Tests\Fixtures\FixtureFactory;
1616
use League\Bundle\OAuth2ServerBundle\Tests\TestHelper;
17-
use Nyholm\Psr7\Response;
17+
use Symfony\Component\HttpFoundation\Response;
1818

1919
final class AuthorizationEndpointTest extends AbstractAcceptanceTest
2020
{
@@ -303,8 +303,9 @@ public function testCodeRequestRedirectToResolutionUri(): void
303303
->getContainer()
304304
->get('event_dispatcher')
305305
->addListener(OAuth2Events::AUTHORIZATION_REQUEST_RESOLVE, static function (AuthorizationRequestResolveEvent $event): void {
306-
$response = (new Response())->withStatus(302)->withHeader('Location', '/authorize/consent');
307-
$event->setResponse($response);
306+
$event->setResponse(new Response(null, 302, [
307+
'Location' => '/authorize/consent',
308+
]));
308309
});
309310

310311
$this->client->request(
@@ -335,8 +336,9 @@ public function testAuthorizationRequestEventIsStoppedAfterSettingAResponse(): v
335336
$event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_APPROVED);
336337
}, 100);
337338
$eventDispatcher->addListener(OAuth2Events::AUTHORIZATION_REQUEST_RESOLVE, static function (AuthorizationRequestResolveEvent $event): void {
338-
$response = (new Response())->withStatus(302)->withHeader('Location', '/authorize/consent');
339-
$event->setResponse($response);
339+
$event->setResponse(new Response(null, 302, [
340+
'Location' => '/authorize/consent',
341+
]));
340342
}, 200);
341343

342344
$this->client->request(
@@ -365,8 +367,11 @@ public function testAuthorizationRequestEventIsStoppedAfterResolution(): void
365367
$event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_APPROVED);
366368
}, 200);
367369
$eventDispatcher->addListener(OAuth2Events::AUTHORIZATION_REQUEST_RESOLVE, static function (AuthorizationRequestResolveEvent $event): void {
368-
$response = (new Response())->withStatus(302)->withHeader('Location', '/authorize/consent');
369-
$event->setResponse($response);
370+
$event->setResponse(
371+
new Response(null, 302, [
372+
'Location' => '/authorize/consent',
373+
])
374+
);
370375
}, 100);
371376

372377
$this->client->request(

0 commit comments

Comments
 (0)