Skip to content

Commit ef1ae45

Browse files
Merge branch '7.4' into 8.0
* 7.4: (28 commits) [Messenger] Allow Pheanstalk v8 [TypeInfo] Fix resolving constructor type with templates fix compatibility with RelayCluster 0.12 fix type alias with template resolving fix compatibility with RelayCluster 0.11 and 0.12 [DependencyInjection] Register a custom autoloader to generate `*Config` classes when they don't exist yet [Security] Add security:oidc-token:generate command [PropertyInfo][TypeInfo] Fix resolving constructor type with templates [WebProfilerBundle] ”finish” errored requests Add support for union types on AsEventListener [Console] Update CHANGELOG to reflect attribute name changes for interactive invokable commands bump ext-redis to 6.2 and ext-relay to 0.12 minimum [TypeInfo] Fix type alias with template resolving [Console] Add support for interactive invokable commands with `#[Interact]` and `#[Ask]` attributes bump ext-relay to 0.12+ fix merge [Config] Generate the array-shape of the current node instead of the whole root node in Config classes [HttpFoundation] Deprecate Request::get() in favor of using properties ->attributes, query or request directly fix Relay Cluster 0.12 compatibility [TypeInfo] ArrayShape can resolve key type as callable instead of string ...
2 parents d332665 + d3f86d0 commit ef1ae45

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

DependencyInjection/Security/AccessToken/OidcTokenHandlerFactory.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Exception\LogicException;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\Security\Http\Command\OidcTokenGenerateCommand;
2021
use Symfony\Contracts\HttpClient\HttpClientInterface;
2122

2223
/**
@@ -78,6 +79,33 @@ public function create(ContainerBuilder $container, string $id, array|string $co
7879
]
7980
);
8081
}
82+
83+
// Generate command
84+
if (!class_exists(OidcTokenGenerateCommand::class)) {
85+
return;
86+
}
87+
88+
if (!$container->hasDefinition('security.access_token_handler.oidc.command.generate')) {
89+
$container
90+
->register('security.access_token_handler.oidc.command.generate', OidcTokenGenerateCommand::class)
91+
->addTag('console.command')
92+
;
93+
}
94+
95+
$firewall = substr($id, strlen('security.access_token_handler.'));
96+
$container->getDefinition('security.access_token_handler.oidc.command.generate')
97+
->addMethodCall('addGenerator', [
98+
$firewall,
99+
(new ChildDefinition('security.access_token_handler.oidc.generator'))
100+
->replaceArgument(0, (new ChildDefinition('security.access_token_handler.oidc.signature'))->replaceArgument(0, $config['algorithms']))
101+
->replaceArgument(1, (new ChildDefinition('security.access_token_handler.oidc.jwkset'))->replaceArgument(0, $config['keyset']))
102+
->replaceArgument(2, $config['audience'])
103+
->replaceArgument(3, $config['issuers'])
104+
->replaceArgument(4, $config['claim']),
105+
$config['algorithms'],
106+
$config['issuers'],
107+
])
108+
;
81109
}
82110

83111
public function getKey(): string

Resources/config/security_authenticator_access_token.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
use Symfony\Component\Security\Http\AccessToken\FormEncodedBodyExtractor;
3838
use Symfony\Component\Security\Http\AccessToken\HeaderAccessTokenExtractor;
3939
use Symfony\Component\Security\Http\AccessToken\OAuth2\Oauth2TokenHandler;
40+
use Symfony\Component\Security\Http\AccessToken\Oidc\OidcTokenGenerator;
4041
use Symfony\Component\Security\Http\AccessToken\Oidc\OidcTokenHandler;
4142
use Symfony\Component\Security\Http\AccessToken\Oidc\OidcUserInfoTokenHandler;
4243
use Symfony\Component\Security\Http\AccessToken\QueryAccessTokenExtractor;
4344
use Symfony\Component\Security\Http\Authenticator\AccessTokenAuthenticator;
45+
use Symfony\Component\Security\Http\Command\OidcTokenGenerateCommand;
4446
use Symfony\Contracts\HttpClient\HttpClientInterface;
4547

4648
return static function (ContainerConfigurator $container) {
@@ -200,5 +202,16 @@
200202
service('http_client'),
201203
service('logger')->nullOnInvalid(),
202204
])
205+
206+
->set('security.access_token_handler.oidc.generator', OidcTokenGenerator::class)
207+
->abstract()
208+
->args([
209+
abstract_arg('signature algorithm'),
210+
abstract_arg('signature key'),
211+
abstract_arg('audience'),
212+
abstract_arg('issuers'),
213+
abstract_arg('claim'),
214+
service('clock'),
215+
])
203216
;
204217
};

Tests/DependencyInjection/Security/Factory/AccessTokenFactoryTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\DependencyInjection\ContainerBuilder;
2626
use Symfony\Component\DependencyInjection\Exception\LogicException;
2727
use Symfony\Component\DependencyInjection\Reference;
28+
use Symfony\Component\Security\Http\AccessToken\Oidc\OidcTokenGenerator;
2829
use Symfony\Contracts\HttpClient\HttpClientInterface;
2930

3031
class AccessTokenFactoryTest extends TestCase
@@ -511,4 +512,52 @@ private function createTokenHandlerFactories(): array
511512
new OAuth2TokenHandlerFactory(),
512513
];
513514
}
515+
516+
public function testOidcTokenGenerator()
517+
{
518+
if (!class_exists(OidcTokenGenerator::class)) {
519+
$this->markTestSkipped('OidcTokenGenerator not available.');
520+
}
521+
522+
$container = new ContainerBuilder();
523+
$jwkset = '{"keys":[{"kty":"EC","crv":"P-256","x":"FtgMtrsKDboRO-Zo0XC7tDJTATHVmwuf9GK409kkars","y":"rWDE0ERU2SfwGYCo1DWWdgFEbZ0MiAXLRBBOzBgs_jY","d":"4G7bRIiKih0qrFxc0dtvkHUll19tTyctoCR3eIbOrO0"},{"kty":"EC","crv":"P-256","x":"0QEAsI1wGI-dmYatdUZoWSRWggLEpyzopuhwk-YUnA4","y":"KYl-qyZ26HobuYwlQh-r0iHX61thfP82qqEku7i0woo","d":"iA_TV2zvftni_9aFAQwFO_9aypfJFCSpcCyevDvz220"}]}';
524+
$config = [
525+
'token_handler' => [
526+
'oidc' => [
527+
'algorithms' => ['RS256', 'ES256'],
528+
'issuers' => ['https://www.example.com'],
529+
'audience' => 'audience',
530+
'keyset' => $jwkset,
531+
],
532+
],
533+
];
534+
535+
$factory = new AccessTokenFactory($this->createTokenHandlerFactories());
536+
$finalizedConfig = $this->processConfig($config, $factory);
537+
538+
$factory->createAuthenticator($container, 'firewall1', $finalizedConfig, 'userprovider');
539+
540+
$this->assertTrue($container->hasDefinition('security.access_token_handler.oidc.command.generate'));
541+
$this->assertTrue($container->getDefinition('security.access_token_handler.oidc.command.generate')->hasMethodCall('addGenerator'));
542+
}
543+
544+
public function testOidcTokenGeneratorCommandWithNoTokenHandler()
545+
{
546+
$container = new ContainerBuilder();
547+
$config = [
548+
'token_handler' => [
549+
'oidc_user_info' => [
550+
'base_uri' => 'https://www.example.com/realms/demo/protocol/openid-connect/userinfo',
551+
'client' => 'oidc.client',
552+
],
553+
],
554+
];
555+
556+
$factory = new AccessTokenFactory($this->createTokenHandlerFactories());
557+
$finalizedConfig = $this->processConfig($config, $factory);
558+
559+
$factory->createAuthenticator($container, 'firewall1', $finalizedConfig, 'userprovider');
560+
561+
$this->assertFalse($container->hasDefinition('security.access_token_handler.oidc.command.generate'));
562+
}
514563
}

0 commit comments

Comments
 (0)