Skip to content

Commit

Permalink
Support RSA algorithm signature
Browse files Browse the repository at this point in the history
  • Loading branch information
louismariegaborit committed Jan 30, 2024
1 parent e172491 commit bc94265
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Mark class `ExpressionCacheWarmer` as `final`
* Support RSA algorithm for oidc token signature

7.0
---
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function create(ContainerBuilder $container, string $id, array|string $co

// @see Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SignatureAlgorithmFactory
// for supported algorithms
if (\in_array($config['algorithm'], ['ES256', 'ES384', 'ES512'], true)) {
if (\in_array($config['algorithm'], ['ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512'], true)) {
$tokenHandlerDefinition->replaceArgument(0, new Reference('security.access_token_handler.oidc.signature.'.$config['algorithm']));
} else {
$tokenHandlerDefinition->replaceArgument(0, (new ChildDefinition('security.access_token_handler.oidc.signature'))
Expand Down
Expand Up @@ -35,9 +35,20 @@ public static function create(string $algorithm): AlgorithmInterface

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

return new $algorithm();
}
break;
case 'RS256':
case 'RS384':
case 'RS512':
if (!class_exists(Algorithm::class.'\\'.$algorithm)) {
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));
}

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));
$algorithm = Algorithm::class.'\\'.$algorithm;
break;
default:
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));
}

return new $algorithm();
}
}
Expand Up @@ -16,6 +16,9 @@
use Jose\Component\Signature\Algorithm\ES256;
use Jose\Component\Signature\Algorithm\ES384;
use Jose\Component\Signature\Algorithm\ES512;
use Jose\Component\Signature\Algorithm\RS256;
use Jose\Component\Signature\Algorithm\RS384;
use Jose\Component\Signature\Algorithm\RS512;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SignatureAlgorithmFactory;
use Symfony\Component\Security\Http\AccessToken\ChainAccessTokenExtractor;
use Symfony\Component\Security\Http\AccessToken\FormEncodedBodyExtractor;
Expand Down Expand Up @@ -100,5 +103,17 @@
->set('security.access_token_handler.oidc.signature.ES512', ES512::class)
->parent('security.access_token_handler.oidc.signature')
->args(['index_0' => 'ES512'])

->set('security.access_token_handler.oidc.signature.RS256', RS256::class)
->parent('security.access_token_handler.oidc.signature')
->args(['index_0' => 'RS256'])

->set('security.access_token_handler.oidc.signature.RS384', RS384::class)
->parent('security.access_token_handler.oidc.signature')
->args(['index_0' => 'RS384'])

->set('security.access_token_handler.oidc.signature.RS512', RS512::class)
->parent('security.access_token_handler.oidc.signature')
->args(['index_0' => 'RS512'])
;
};
3 changes: 2 additions & 1 deletion src/Symfony/Component/Security/Http/composer.json
Expand Up @@ -35,7 +35,8 @@
"symfony/translation": "^6.4|^7.0",
"psr/log": "^1|^2|^3",
"web-token/jwt-checker": "^3.1",
"web-token/jwt-signature-algorithm-ecdsa": "^3.1"
"web-token/jwt-signature-algorithm-ecdsa": "^3.1",
"web-token/jwt-signature-algorithm-rsa": "^3.1",
},
"conflict": {
"symfony/clock": "<6.4",
Expand Down

0 comments on commit bc94265

Please sign in to comment.