fix: JWT config setters#385
Merged
Merged
Conversation
…oot-only setAlgo, setSecret, and setKeys now call a protected onConfigurationChanged hook so subclasses that cache derived state can rebuild it. The base implementation is a no-op. Also adds docblock warnings noting that providers are cached on the singleton JWTManager.
Override onConfigurationChanged to rebuild $signer (depends on $algo) then $config (depends on $signer plus the key material) so setAlgo, setSecret, and setKeys actually take effect. Previously these setters were silent no-ops because Lcobucci cached both derived properties in the constructor and never recomputed them.
Three behavioral tests: setAlgo (verifies JWT header alg field reflects the new algorithm), setSecret (verifies the new secret signs and the old one can no longer verify), and setKeys (asymmetric variant using two RSA keypairs). Also moves the keypair helper paths to tests/JWT/Fixtures/keys, adds alt-keypair helpers, and calls parent::setUp.
Per the porting guide convention that test support files (including non-PHP
files like key material) live under tests/{Package}/Fixtures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the JWT provider setters so changes to the configured algorithm, secret, or asymmetric keys actually take effect when using the Lcobucci provider.
Lcobuccibuilds and caches its signer andConfigurationobject during construction. The inheritedsetAlgo(),setSecret(), andsetKeys()methods only updated the raw provider properties, so the cached signer/configuration continued using the original values. That meant calls such assetSecret()orsetKeys()appeared to succeed via the getters, but newly encoded tokens were still signed with the old signing state.Changes
onConfigurationChanged()hook to the base JWT provider.setAlgo(),setSecret(), andsetKeys().tests/JWT/Fixtures/keys.Tests
Added coverage proving:
setAlgo()changes the algorithm used when encoding tokens.setSecret()signs with the rotated secret, and the old secret no longer verifies the token.setKeys()signs with the rotated asymmetric keypair, and the old keypair no longer verifies the token.setKeys()getter/setter round trip works like the existing algorithm and secret setter tests.