Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 427443b

Browse files
Use psr7-pack to get Flex recipes.
1 parent d5739be commit 427443b

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
"minimum-stability": "stable",
1616
"require": {
1717
"php": ">=8.0",
18-
"nyholm/psr7": "^1.4",
1918
"php-istio/jwt-payload-extractor": "^1.0",
20-
"symfony/psr-http-message-bridge": "^2.1",
19+
"symfony/psr7-pack": "^1.0",
2120
"symfony/security-bundle": "^5.3"
2221
},
2322
"autoload": {

src/Authenticator/Authenticator.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
namespace Istio\Symfony\JWTAuthentication\Authenticator;
1212

1313
use Istio\Symfony\JWTAuthentication\User\JWTPayloadAwareUserProviderInterface;
14-
use Nyholm\Psr7\Factory\Psr17Factory;
15-
use Psr\Http\Message\ServerRequestInterface;
16-
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
14+
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1715
use Symfony\Component\HttpFoundation\Request;
1816
use Symfony\Component\HttpFoundation\Response;
1917
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -29,13 +27,14 @@ final class Authenticator extends AbstractAuthenticator implements Authenticatio
2927
{
3028
public function __construct(
3129
private iterable $userIdentifierClaimMappings,
32-
private UserProviderInterface $userProvider
30+
private UserProviderInterface $userProvider,
31+
private HttpMessageFactoryInterface $httpMessageFactory
3332
) {
3433
}
3534

3635
public function supports(Request $request): ?bool
3736
{
38-
$psr7Request = $this->normalizeRequest($request);
37+
$psr7Request = $this->httpMessageFactory->createRequest($request);
3938

4039
foreach ($this->userIdentifierClaimMappings as $mapping) {
4140
/** @var UserIdentifierClaimMapping $mapping */
@@ -103,12 +102,4 @@ public function start(Request $request, AuthenticationException $authException =
103102
{
104103
return new Response('Istio JWT in request\'s missing or invalid.', Response::HTTP_UNAUTHORIZED);
105104
}
106-
107-
private function normalizeRequest(Request $request): ServerRequestInterface
108-
{
109-
$psr17Factory = new Psr17Factory();
110-
$psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
111-
112-
return $psrHttpFactory->createRequest($request);
113-
}
114105
}

src/Resources/config/security.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212

1313
use Istio\Symfony\JWTAuthentication\Authenticator\Authenticator;
1414
use Istio\Symfony\JWTAuthentication\User\StatelessUserProvider;
15+
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1516

1617
return static function (ContainerConfigurator $container) {
1718
$container->services()
1819
->set('istio.jwt_authentication.authenticator', Authenticator::class)
1920
->abstract()
2021
->arg(0, abstract_arg('user identifier claim mappings'))
2122
->arg(1, abstract_arg('user provider'))
23+
->arg(2, service(HttpMessageFactoryInterface::class))
2224

2325
->set('istio.jwt_authentication.stateless_user_provider', StatelessUserProvider::class)
2426
->abstract()

tests/TestKernel.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
use Istio\Symfony\JWTAuthentication\JWTAuthenticationBundle;
1414
use Istio\Symfony\JWTAuthentication\Tests\Fixtures\SecureController;
1515
use Istio\Symfony\JWTAuthentication\Tests\Fixtures\StatelessUser;
16+
use Nyholm\Psr7\Factory\Psr17Factory;
17+
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
18+
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1619
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1720
use Symfony\Bundle\SecurityBundle\SecurityBundle;
1821
use Symfony\Component\Config\Loader\LoaderInterface;
1922
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
2023
use Symfony\Component\DependencyInjection\ContainerBuilder;
24+
use Symfony\Component\DependencyInjection\Reference;
2125
use Symfony\Component\HttpKernel\Kernel;
2226
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2327

@@ -130,16 +134,10 @@ private function publicServices(ContainerBuilder $container)
130134
$container->getDefinition('security.authenticator.manager.test2')->setPublic(true);
131135
}
132136

133-
protected function build(ContainerBuilder $container)
134-
{
135-
parent::build($container);
136-
137-
$this->registerFixtures($container);
138-
}
139-
140137
public function process(ContainerBuilder $container)
141138
{
142139
$this->publicServices($container);
140+
$this->registerFixtures($container);
143141
}
144142

145143
private function registerFixtures(ContainerBuilder $container)
@@ -148,5 +146,12 @@ private function registerFixtures(ContainerBuilder $container)
148146
->register('secure_controller', SecureController::class)
149147
->setPublic(true)
150148
->addTag('controller.service_arguments');
149+
150+
$container->register(Psr17Factory::class, Psr17Factory::class);
151+
152+
$psr17Factory = new Reference(Psr17Factory::class);
153+
$container
154+
->register(HttpMessageFactoryInterface::class, PsrHttpFactory::class)
155+
->setArguments([$psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory]);
151156
}
152157
}

tests/Unit/Authenticator/AuthenticatorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Istio\Symfony\JWTAuthentication\Authenticator\UserIdentifierClaimMapping;
1616
use Istio\Symfony\JWTAuthentication\Tests\Fixtures\TokenTrait;
1717
use Istio\Symfony\JWTAuthentication\User\JWTPayloadAwareUserProviderInterface;
18+
use Nyholm\Psr7\Factory\Psr17Factory;
1819
use PHPUnit\Framework\TestCase;
20+
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
1921
use Symfony\Component\HttpFoundation\Request;
2022
use Symfony\Component\Security\Core\User\InMemoryUser;
2123
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
@@ -210,7 +212,10 @@ private function createAuthenticatorWithInMemoryUserProvider(array $users): Auth
210212

211213
private function createAuthenticator(UserProviderInterface $userProvider): Authenticator
212214
{
213-
return new Authenticator($this->getUserIdentifierClaimMappings(), $userProvider);
215+
$psr17Factory = new Psr17Factory();
216+
$psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
217+
218+
return new Authenticator($this->getUserIdentifierClaimMappings(), $userProvider, $psrHttpFactory);
214219
}
215220

216221
private function getUserIdentifierClaimMappings(): array

0 commit comments

Comments
 (0)