feat: add should_handle hook for JWT client auth algorithm routing#894
Open
liudonggalaxy wants to merge 1 commit into
Open
feat: add should_handle hook for JWT client auth algorithm routing#894liudonggalaxy wants to merge 1 commit into
liudonggalaxy wants to merge 1 commit into
Conversation
09777d6 to
7151349
Compare
Add a 'should_handle(headers, claims)' method to JWTBearerClientAssertion that subclasses can override to filter JWT assertions by algorithm type. This enables registering separate handlers for symmetric (client_secret_jwt) and asymmetric (private_key_jwt) algorithms on the same authorization server. When should_handle returns False, the handler returns None, allowing the authentication framework to try the next registered method. The default implementation returns True, maintaining full backward compatibility. This pattern is useful for servers that need to support both client_secret_jwt (HS256/384/512) and private_key_jwt (RS256, ES256, EdDSA) simultaneously with different key resolution logic for each. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7151349 to
5181148
Compare
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.
What kind of change does this PR introduce?
This is a feature implementation.
Description
Add a
should_handle(headers, claims)method toJWTBearerClientAssertionthat subclasses can override to filter JWT assertions by algorithm type. This enables registering separate handlers forclient_secret_jwt(symmetric) andprivate_key_jwt(asymmetric) on the same authorization server.When both auth methods use the same
client_assertion_type(urn:ietf:params:oauth:client-assertion-type:jwt-bearer), the server must inspect the JWTalgheader to route to the correct handler. Without this hook, the first registered handler may attempt verification with the wrong key type and raiseInvalidClientError, preventing the correct handler from being tried.Usage:
The default
should_handle()returnsTrue, maintaining full backward compatibility.Checklist
prek.pragma: no cover