8000 Support RSA algorithm signature · symfony/symfony@bc94265 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc94265

Browse files
Support RSA algorithm signature
1 parent e172491 commit bc94265

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Mark class `ExpressionCacheWarmer` as `final`
8+
* Support RSA algorithm for oidc token signature
89

910
7.0
1011
---

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/AccessToken/OidcTokenHandlerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function create(ContainerBuilder $container, string $id, array|string $co
3737

3838
// @see Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SignatureAlgorithmFactory
3939
// for supported algorithms
40-
if (\in_array($config['algorithm'], ['ES256', 'ES384', 'ES512'], true)) {
40+
if (\in_array($config['algorithm'], ['ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512'], true)) {
4141
$tokenHandlerDefinition->replaceArgument(0, new Reference('security.access_token_handler.oidc.signature.'.$config['algorithm']));
4242
} else {
4343
$tokenHandlerDefinition->replaceArgument(0, (new ChildDefinition('security.access_token_handler.oidc.signature'))

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SignatureAlgorithmFactory.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,20 @@ public static function create(string $algorithm): AlgorithmInterface
3535

3636
$algorithm = Algorithm::class.'\\'.$algorithm;
3737

38-
return new $algorithm();
39< 10000 /code>-
}
38+
break;
39+
case 'RS256':
40+
case 'RS384':
41+
case 'RS512':
42+
if (!class_exists(Algorithm::class.'\\'.$algorithm)) {
43+
throw new \LogicException(sprintf('You cannot use the "%s" signature algorithm since "web-token/jwt-signature-algorithm-rsa" is not installed. Try running "composer require web-token/jwt-signature-algorithm-rsa".', $algorithm));
44+
}
4045

41-
throw new InvalidArgumentException(sprintf('Unsupported signature algorithm "%s". Only ES* algorithms are supported. If you want to use another algorithm, create your TokenHandler as a service.', $algorithm));
46+
$algorithm = Algorithm::class.'\\'.$algorithm;
47+
break;
48+
default:
49+
throw new InvalidArgumentException(sprintf('Unsupported signature algorithm "%s". Only ES* and RS256 algorithms are supported. If you want to use another algorithm, create your TokenHandler as a service.', $algorithm));
50+
}
51+
52+
return new $algorithm();
4253
}
4354
}

src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator_access_token.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Jose\Component\Signature\Algorithm\ES256;
1717
use Jose\Component\Signature\Algorithm\ES384;
1818
use Jose\Component\Signature\Algorithm\ES512;
19+
use Jose\Component\Signature\Algorithm\RS256;
20+
use Jose\Component\Signature\Algorithm\RS384;
21+
use Jose\Component\Signature\Algorithm\RS512;
1922
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SignatureAlgorithmFactory;
2023
use Symfony\Component\Security\Http\AccessToken\ChainAccessTokenExtractor;
2124
use Symfony\Component\Security\Http\AccessToken\FormEncodedBodyExtractor;
@@ -100,5 +103,17 @@
100103
->set('security.access_token_handler.oidc.signature.ES512', ES512::class)
101104
->parent('security.access_token_handler.oidc.signature')
102105
->args(['index_0' => 'ES512'])
106+
107+
->set('security.access_token_handler.oidc.signature.RS256', RS256::class)
108+
->parent('security.access_token_handler.oidc.signature')
109+
->args(['index_0' => 'RS256'])
110+
111+
->set('security.access_token_handler.oidc.signature.RS384', RS384::class)
112+
->parent('security.access_token_handler.oidc.signature')
113+
->args(['index_0' => 'RS384'])
114+
115+
->set('security.access_token_handler.oidc.signature.RS512', RS512::class)
116+
->parent('security.access_token_handler.oidc.signature')
117+
->args(['index_0' => 'RS512'])
103118
;
104119
};

src/Symfony/Component/Security/Http/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"symfony/translation": "^6.4|^7.0",
3636
"psr/log": "^1|^2|^3",
3737
"web-token/jwt-checker": "^3.1",
38-
"web-token/jwt-signature-algorithm-ecdsa": "^3.1"
38+
"web-token/jwt-signature-algorithm-ecdsa": "^3.1",
39+
"web-token/jwt-signature-algorithm-rsa": "^3.1",
3940
},
4041
"conflict": {
4142
"symfony/clock": "<6.4",

0 commit comments

Comments
 (0)
0