Skip to content

[SecurityBundle] Remove deprecated OIDC token handler options algorithm and key #60929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,21 @@ SecurityBundle
- `'account_status'`: A new option that only exposes account status errors (e.g., account locked, disabled)

* Make `ExpressionCacheWarmer` class `final`
* Remove the deprecated `algorithm` and `key` options from the OIDC token handler configuration, use `algorithms` and `keyset` instead

```diff
# config/packages/security.yaml
security:
firewalls:
main:
access_token:
token_handler:
oidc:
- algorithm: 'RS256'
- key: 'https://example.com/.well-known/jwks.json'
+ algorithms: ['RS256']
+ keyset: 'https://example.com/.well-known/jwks.json'
```

Serializer
----------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Remove the deprecated `hide_user_not_found` configuration option, use `expose_security_errors` instead
* Remove the deprecated `algorithm` and `key` options from the OIDC token handler configuration, use `algorithms` and `keyset` instead
* Remove `LazyFirewallContext::__invoke()`
* Make `ExpressionCacheWarmer` class `final`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,8 @@ public function addConfiguration(NodeBuilder $node): void
->arrayNode($this->getKey())
->fixXmlConfig($this->getKey())
->validate()
->ifTrue(static fn ($v) => !isset($v['algorithm']) && !isset($v['algorithms']))
->thenInvalid('You must set either "algorithm" or "algorithms".')
->end()
->validate()
->ifTrue(static fn ($v) => !isset($v['discovery']) && !isset($v['key']) && !isset($v['keyset']))
->thenInvalid('You must set either "discovery" or "key" or "keyset".')
->end()
->beforeNormalization()
->ifTrue(static fn ($v) => isset($v['algorithm']) && \is_string($v['algorithm']))
->then(static function ($v) {
if (isset($v['algorithms'])) {
throw new InvalidConfigurationException('You cannot use both "algorithm" and "algorithms" at the same time.');
}
$v['algorithms'] = [$v['algorithm']];
unset($v['algorithm']);

return $v;
})
->end()
->beforeNormalization()
->ifTrue(static fn ($v) => isset($v['key']) && \is_string($v['key']))
->then(static function ($v) {
if (isset($v['keyset'])) {
throw new InvalidConfigurationException('You cannot use both "key" and "keyset" at the same time.');
}
$v['keyset'] = \sprintf('{"keys":[%s]}', $v['key']);

return $v;
})
->ifTrue(static fn ($v) => !isset($v['discovery']) && !isset($v['keyset']))
->thenInvalid('You must set either "discovery" or "keyset".')
->end()
->children()
->arrayNode('discovery')
Expand Down Expand Up @@ -155,19 +128,11 @@ public function addConfiguration(NodeBuilder $node): void
->isRequired()
->scalarPrototype()->end()
->end()
->arrayNode('algorithm')
->info('Algorithm used to sign the token.')
->setDeprecated('symfony/security-bundle', '7.1', 'The "%node%" option is deprecated and will be removed in 8.0. Use the "algorithms" option instead.')
->end()
->arrayNode('algorithms')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need fixXmlConfig('algorithm') to convert the single to plural for the XML format for the prototyped node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->info('Algorithms used to sign the token.')
->isRequired()
->scalarPrototype()->end()
->end()
->scalarNode('key')
->info('JSON-encoded JWK used to sign the token (must contain a "kty" key).')
->setDeprecated('symfony/security-bundle', '7.1', 'The "%node%" option is deprecated and will be removed in 8.0. Use the "keyset" option instead.')
->end()
->scalarNode('keyset')
->info('JSON-encoded JWKSet used to sign the token (must contain a list of valid public keys).')
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,61 +104,17 @@ public function testInvalidOidcTokenHandlerConfigurationKeyMissing()
$config = [
'token_handler' => [
'oidc' => [
'algorithm' => 'RS256',
'issuers' => ['https://www.example.com'],
'audience' => 'audience',
],
],
];

$factory = new AccessTokenFactory($this->createTokenHandlerFactories());

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('You must set either "discovery" or "key" or "keyset".');

$this->processConfig($config, $factory);
}

public function testInvalidOidcTokenHandlerConfigurationDuplicatedKeyParameters()
{
$config = [
'token_handler' => [
'oidc' => [
'algorithm' => 'RS256',
'issuers' => ['https://www.example.com'],
'audience' => 'audience',
'key' => 'key',
'keyset' => 'keyset',
],
],
];

$factory = new AccessTokenFactory($this->createTokenHandlerFactories());

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('You cannot use both "key" and "keyset" at the same time.');

$this->processConfig($config, $factory);
}

public function testInvalidOidcTokenHandlerConfigurationDuplicatedAlgorithmParameters()
{
$config = [
'token_handler' => [
'oidc' => [
'algorithm' => 'RS256',
'algorithms' => ['RS256'],
'issuers' => ['https://www.example.com'],
'audience' => 'audience',
'keyset' => 'keyset',
],
],
];

$factory = new AccessTokenFactory($this->createTokenHandlerFactories());

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('You cannot use both "algorithm" and "algorithms" at the same time.');
$this->expectExceptionMessage('You must set either "discovery" or "keyset".');

$this->processConfig($config, $factory);
}
Expand All @@ -183,46 +139,6 @@ public function testInvalidOidcTokenHandlerConfigurationMissingAlgorithmParamete
$this->processConfig($config, $factory);
}

/**
* @group legacy
*
* @expectedDeprecation Since symfony/security-bundle 7.1: The "key" option is deprecated and will be removed in 8.0. Use the "keyset" option instead.
*/
public function testOidcTokenHandlerConfigurationWithSingleAlgorithm()
{
$container = new ContainerBuilder();
$jwk = '{"kty":"EC","crv":"P-256","x":"0QEAsI1wGI-dmYatdUZoWSRWggLEpyzopuhwk-YUnA4","y":"KYl-qyZ26HobuYwlQh-r0iHX61thfP82qqEku7i0woo","d":"iA_TV2zvftni_9aFAQwFO_9aypfJFCSpcCyevDvz220"}';
$config = [
'token_handler' => [
'oidc' => [
'algorithm' => 'RS256',
'issuers' => ['https://www.example.com'],
'audience' => 'audience',
'key' => $jwk,
],
],
];

$factory = new AccessTokenFactory($this->createTokenHandlerFactories());
$finalizedConfig = $this->processConfig($config, $factory);

$factory->createAuthenticator($container, 'firewall1', $finalizedConfig, 'userprovider');

$this->assertTrue($container->hasDefinition('security.authenticator.access_token.firewall1'));
$this->assertTrue($container->hasDefinition('security.access_token_handler.firewall1'));

$expected = [
'index_0' => (new ChildDefinition('security.access_token_handler.oidc.signature'))
->replaceArgument(0, ['RS256']),
'index_1' => (new ChildDefinition('security.access_token_handler.oidc.jwkset'))
->replaceArgument(0, \sprintf('{"keys":[%s]}', $jwk)),
'index_2' => 'audience',
'index_3' => ['https://www.example.com'],
'index_4' => 'sub',
];
$this->assertEquals($expected, $container->getDefinition('security.access_token_handler.firewall1')->getArguments());
}

public function testOidcTokenHandlerConfigurationWithMultipleAlgorithms()
{
$container = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ security:
claim: 'username'
audience: 'Symfony OIDC'
issuers: [ 'https://www.example.com' ]
algorithm: 'ES256'
algorithms: ['ES256']
# tip: use https://mkjwk.org/ to generate a JWK
keyset: '{"keys":[{"kty":"EC","d":"iA_TV2zvftni_9aFAQwFO_9aypfJFCSpcCyevDvz220","crv":"P-256","x":"0QEAsI1wGI-dmYatdUZoWSRWggLEpyzopuhwk-YUnA4","y":"KYl-qyZ26HobuYwlQh-r0iHX61thfP82qqEku7i0woo"}]}'
encryption:
Expand Down
Loading