From f79518512854c71097b15784caf4fd674a6419c7 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 11 Apr 2024 19:28:08 +0200 Subject: [PATCH] Update OidcTokenHandler dependencies and configuration This commit replaces the individual jwt packages previously needed by 'OidcTokenHandler' with the `web-token/jwt-library`. Configuration changes have been made to support multiple signing algorithms and a keyset instead of a single key. These changes provide more flexibility and reliability for token handling and verification. --- security/access_token.rst | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/security/access_token.rst b/security/access_token.rst index 5057e243c25..593c6404c7a 100644 --- a/security/access_token.rst +++ b/security/access_token.rst @@ -537,15 +537,12 @@ claims. To create your own user object from the claims, you must 2) Configure the OidcTokenHandler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The ``OidcTokenHandler`` requires ``web-token/jwt-signature``, -``web-token/jwt-checker`` and ``web-token/jwt-signature-algorithm-ecdsa`` -packages. If you haven't installed them yet, run these commands: +The ``OidcTokenHandler`` requires the package ``web-token/jwt-library``. +If you haven't installed it yet, run this command: .. code-block:: terminal - $ composer require web-token/jwt-signature - $ composer require web-token/jwt-checker - $ composer require web-token/jwt-signature-algorithm-ecdsa + $ composer require web-token/jwt-library Symfony provides a generic ``OidcTokenHandler`` to decode your token, validate it and retrieve the user info from it: @@ -561,10 +558,10 @@ it and retrieve the user info from it: access_token: token_handler: oidc: - # Algorithm used to sign the JWS - algorithm: 'ES256' + # Algorithms used to sign the JWS + algorithms: ['ES256', 'RS256'] # A JSON-encoded JWK - key: '{"kty":"...","k":"..."}' + keyset: '{"keys":[{"kty":"...","k":"..."}]}' # Audience (`aud` claim): required for validation purpose audience: 'api-example' # Issuers (`iss` claim): required for validation purpose @@ -589,8 +586,10 @@ it and retrieve the user info from it: - + + ES256 + RS256 https://oidc.example.com @@ -610,9 +609,9 @@ it and retrieve the user info from it: ->tokenHandler() ->oidc() // Algorithm used to sign the JWS - ->algorithm('ES256') + ->algorithms(['ES256', 'RS256']) // A JSON-encoded JWK - ->key('{"kty":"...","k":"..."}') + ->keyset('{"keys":[{"kty":"...","k":"..."}]}') // Audience (`aud` claim): required for validation purpose ->audience('api-example') // Issuers (`iss` claim): required for validation purpose @@ -636,8 +635,8 @@ configuration: token_handler: oidc: claim: email - algorithm: 'ES256' - key: '{"kty":"...","k":"..."}' + algorithms: ['ES256', 'RS256'] + keyset: '{"keys":[{"kty":"...","k":"..."}]}' audience: 'api-example' issuers: ['https://oidc.example.com'] @@ -657,7 +656,9 @@ configuration: - + + ES256 + RS256 https://oidc.example.com @@ -677,8 +678,8 @@ configuration: ->tokenHandler() ->oidc() ->claim('email') - ->algorithm('ES256') - ->key('{"kty":"...","k":"..."}') + ->algorithms(['ES256', 'RS256']) + ->keyset('{"keys":[{"kty":"...","k":"..."}]}') ->audience('api-example') ->issuers(['https://oidc.example.com']) ;