Skip to content

Commit fb84011

Browse files
committed
Drop SensioFrameworkExtraBundle
1 parent 5c997bb commit fb84011

File tree

7 files changed

+96
-116
lines changed

7 files changed

+96
-116
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Fork of trikoder/oauth2-bundle, for the better.
1010

1111
## Quick Start
1212

13-
1. Require the bundle and a PSR 7/17 implementation using Composer:
13+
1. Require the bundle using Composer:
1414

1515
```sh
16-
composer require league/oauth2-server-bundle nyholm/psr7
16+
composer require league/oauth2-server-bundle
1717
```
1818

1919
## Documentation

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@
2020
"doctrine/doctrine-bundle": "^2.0",
2121
"doctrine/orm": "^2.7",
2222
"league/oauth2-server": "^8.0",
23+
"nyholm/psr7": "^1.4",
2324
"psr/http-factory": "^1.0",
24-
"sensio/framework-extra-bundle": "^5.6",
2525
"symfony/framework-bundle": "^4.4|^5.0",
2626
"symfony/psr-http-message-bridge": "^2.0",
2727
"symfony/security-bundle": "^4.4|^5.0"
2828
},
2929
"require-dev": {
3030
"ext-pdo": "*",
3131
"ext-pdo_sqlite": "*",
32-
"laminas/laminas-diactoros": "^2.2",
33-
"nyholm/psr7": "^1.2",
3432
"psalm/plugin-symfony": "^2.2",
3533
"symfony/browser-kit": "^4.4|^5.0",
3634
"symfony/phpunit-bridge": "^5.2",
35+
"symfony/yaml": "^4.4|^5.0",
3736
"vimeo/psalm": "^4.6"
3837
},
3938
"autoload": {

src/Controller/AuthorizationController.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
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;
17-
use Psr\Http\Message\ServerRequestInterface;
16+
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
17+
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1818
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19+
use Symfony\Component\HttpFoundation\Request;
20+
use Symfony\Component\HttpFoundation\Response;
1921

2022
final class AuthorizationController
2123
{
@@ -44,23 +46,45 @@ final class AuthorizationController
4446
*/
4547
private $clientManager;
4648

49+
/**
50+
* @var HttpMessageFactoryInterface
51+
*/
52+
private $httpMessageFactory;
53+
54+
/**
55+
* @var HttpFoundationFactoryInterface
56+
*/
57+
private $httpFoundationFactory;
58+
59+
/**
60+
* @var ResponseFactoryInterface
61+
*/
62+
private $responseFactory;
63+
4764
public function __construct(
4865
AuthorizationServer $server,
4966
EventDispatcherInterface $eventDispatcher,
5067
AuthorizationRequestResolveEventFactory $eventFactory,
5168
UserConverterInterface $userConverter,
52-
ClientManagerInterface $clientManager
69+
ClientManagerInterface $clientManager,
70+
HttpMessageFactoryInterface $httpMessageFactory,
71+
HttpFoundationFactoryInterface $httpFoundationFactory,
72+
ResponseFactoryInterface $responseFactory
5373
) {
5474
$this->server = $server;
5575
$this->eventDispatcher = $eventDispatcher;
5676
$this->eventFactory = $eventFactory;
5777
$this->userConverter = $userConverter;
5878
$this->clientManager = $clientManager;
79+
$this->httpMessageFactory = $httpMessageFactory;
80+
$this->httpFoundationFactory = $httpFoundationFactory;
81+
$this->responseFactory = $responseFactory;
5982
}
6083

61-
public function indexAction(ServerRequestInterface $serverRequest, ResponseFactoryInterface $responseFactory): ResponseInterface
84+
public function indexAction(Request $request): Response
6285
{
63-
$serverResponse = $responseFactory->createResponse();
86+
$serverRequest = $this->httpMessageFactory->createRequest($request);
87+
$serverResponse = $this->responseFactory->createResponse();
6488

6589
try {
6690
$authRequest = $this->server->validateAuthorizationRequest($serverRequest);
@@ -69,10 +93,7 @@ public function indexAction(ServerRequestInterface $serverRequest, ResponseFacto
6993
/** @var Client $client */
7094
$client = $this->clientManager->find($authRequest->getClient()->getIdentifier());
7195
if (!$client->isPlainTextPkceAllowed()) {
72-
return OAuthServerException::invalidRequest(
73-
'code_challenge_method',
74-
'Plain code challenge method is not allowed for this client'
75-
)->generateHttpResponse($serverResponse);
96+
throw OAuthServerException::invalidRequest('code_challenge_method', 'Plain code challenge method is not allowed for this client');
7697
}
7798
}
7899

@@ -85,15 +106,16 @@ public function indexAction(ServerRequestInterface $serverRequest, ResponseFacto
85106
$authRequest->setUser($this->userConverter->toLeague($event->getUser()));
86107

87108
if ($event->hasResponse()) {
88-
/** @var ResponseInterface */
89-
return $event->getResponse();
109+
return $this->httpFoundationFactory->createResponse($event->getResponse());
90110
}
91111

92112
$authRequest->setAuthorizationApproved($event->getAuthorizationResolution());
93113

94-
return $this->server->completeAuthorizationRequest($authRequest, $serverResponse);
114+
$response = $this->server->completeAuthorizationRequest($authRequest, $serverResponse);
95115
} catch (OAuthServerException $e) {
96-
return $e->generateHttpResponse($serverResponse);
116+
$response = $e->generateHttpResponse($serverResponse);
97117
}
118+
119+
return $this->httpFoundationFactory->createResponse($response);
98120
}
99121
}

src/Controller/TokenController.php

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use League\OAuth2\Server\AuthorizationServer;
88
use League\OAuth2\Server\Exception\OAuthServerException;
99
use Psr\Http\Message\ResponseFactoryInterface;
10-
use Psr\Http\Message\ResponseInterface;
11-
use Psr\Http\Message\ServerRequestInterface;
10+
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
11+
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
12+
use Symfony\Component\HttpFoundation\Request;
13+
use Symfony\Component\HttpFoundation\Response;
1214

1315
final class TokenController
1416
{
@@ -17,21 +19,44 @@ final class TokenController
1719
*/
1820
private $server;
1921

20-
public function __construct(AuthorizationServer $server)
21-
{
22+
/**
23+
* @var HttpMessageFactoryInterface
24+
*/
25+
private $httpMessageFactory;
26+
27+
/**
28+
* @var HttpFoundationFactoryInterface
29+
*/
30+
private $httpFoundationFactory;
31+
32+
/**
33+
* @var ResponseFactoryInterface
34+
*/
35+
private $responseFactory;
36+
37+
public function __construct(
38+
AuthorizationServer $server,
39+
HttpMessageFactoryInterface $httpMessageFactory,
40+
HttpFoundationFactoryInterface $httpFoundationFactory,
41+
ResponseFactoryInterface $responseFactory
42+
) {
2243
$this->server = $server;
44+
$this->httpMessageFactory = $httpMessageFactory;
45+
$this->httpFoundationFactory = $httpFoundationFactory;
46+
$this->responseFactory = $responseFactory;
2347
}
2448

25-
public function indexAction(
26-
ServerRequestInterface $serverRequest,
27-
ResponseFactoryInterface $responseFactory
28-
): ResponseInterface {
29-
$serverResponse = $responseFactory->createResponse();
49+
public function indexAction(Request $request): Response
50+
{
51+
$serverRequest = $this->httpMessageFactory->createRequest($request);
52+
$serverResponse = $this->responseFactory->createResponse();
3053

3154
try {
32-
return $this->server->respondToAccessTokenRequest($serverRequest, $serverResponse);
55+
$response = $this->server->respondToAccessTokenRequest($serverRequest, $serverResponse);
3356
} catch (OAuthServerException $e) {
34-
return $e->generateHttpResponse($serverResponse);
57+
$response = $e->generateHttpResponse($serverResponse);
3558
}
59+
60+
return $this->httpFoundationFactory->createResponse($response);
3661
}
3762
}

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use League\OAuth2\Server\Grant\PasswordGrant;
2828
use League\OAuth2\Server\Grant\RefreshTokenGrant;
2929
use League\OAuth2\Server\ResourceServer;
30-
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
3130
use Symfony\Bundle\SecurityBundle\SecurityBundle;
3231
use Symfony\Component\Config\FileLocator;
3332
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -117,7 +116,6 @@ private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): v
117116
$requiredBundles = [
118117
'doctrine' => DoctrineBundle::class,
119118
'security' => SecurityBundle::class,
120-
'sensio_framework_extra' => SensioFrameworkExtraBundle::class,
121119
];
122120

123121
foreach ($requiredBundles as $bundleAlias => $requiredBundle) {

src/Resources/config/services.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<service id="League\Bundle\OAuth2ServerBundle\Security\Firewall\OAuth2Listener">
5858
<argument type="service" id="security.token_storage" />
5959
<argument type="service" id="security.authentication.manager" />
60-
<argument type="service" id="sensio_framework_extra.psr7.http_message_factory" />
60+
<argument type="service" id="league.oauth2_server.http_message_factory" />
6161
<argument key="$oauth2TokenFactory" type="service" id="League\Bundle\OAuth2ServerBundle\Security\Authentication\Token\OAuth2TokenFactory" />
6262
</service>
6363

@@ -117,6 +117,9 @@
117117
<argument type="service" id="League\Bundle\OAuth2ServerBundle\Event\AuthorizationRequestResolveEventFactory" />
118118
<argument type="service" id="League\Bundle\OAuth2ServerBundle\Converter\UserConverter" />
119119
<argument type="service" id="League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface" />
120+
<argument type="service" id="league.oauth2_server.http_message_factory" />
121+
<argument type="service" id="league.oauth2_server.http_foundation_factory" />
122+
<argument type="service" id="nyholm.psr7.psr17_factory" />
120123
<tag name="controller.service_arguments" />
121124
</service>
122125

@@ -131,6 +134,9 @@
131134
<!-- Token controller -->
132135
<service id="League\Bundle\OAuth2ServerBundle\Controller\TokenController">
133136
<argument type="service" id="League\OAuth2\Server\AuthorizationServer" />
137+
<argument type="service" id="league.oauth2_server.http_message_factory" />
138+
<argument type="service" id="league.oauth2_server.http_foundation_factory" />
139+
<argument type="service" id="nyholm.psr7.psr17_factory" />
134140
<tag name="controller.service_arguments" />
135141
</service>
136142

@@ -177,5 +183,17 @@
177183
<service id="League\Bundle\OAuth2ServerBundle\Security\Authentication\Token\OAuth2TokenFactory">
178184
<argument type="string" />
179185
</service>
186+
187+
<!-- PSR-7/17 -->
188+
<service id="nyholm.psr7.psr17_factory" class="Nyholm\Psr7\Factory\Psr17Factory" />
189+
190+
<service id="league.oauth2_server.http_message_factory" class="Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory">
191+
<argument type="service" id="nyholm.psr7.psr17_factory" />
192+
<argument type="service" id="nyholm.psr7.psr17_factory" />
193+
<argument type="service" id="nyholm.psr7.psr17_factory" />
194+
<argument type="service" id="nyholm.psr7.psr17_factory" />
195+
</service>
196+
197+
<service id="league.oauth2_server.http_foundation_factory" class="Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory" />
180198
</services>
181199
</container>

0 commit comments

Comments
 (0)