Skip to content

Fall back to the API when a session JWT's signing key is unknown - #322

Open
evan-twilio wants to merge 1 commit into
mainfrom
evan-python-unknown-jwk-fallback
Open

evan-twilio wants to merge 1 commit into
mainfrom
evan-python-unknown-jwk-fallback

Conversation

@evan-twilio

Copy link
Copy Markdown

Session JWT authentication now falls back to the Authenticate API when the SDK can't find a usable signing key for the JWT.

Before this change, authenticate_jwt raised a PyJWKClientError when the JWT's kid wasn't in the JWKS, or when the key type was one PyJWT doesn't support. An expired JWT already falls back to the API, so this PR handles a missing key the same way, for B2C and B2B sessions, sync and async.

RS256 tokens that are signed by a known key are still verified locally. M2M and Connected Apps local verification are unchanged.

This PR also bumps the version to 15.3.1.

Where this fits

This is the first of three steps toward letting Stytch projects sign JWTs with new key types, such as post-quantum keys:

  1. Every backend SDK ignores JWKS keys that it cannot use, so that a new key type in a project's JWKS does not break verification of existing RS256 tokens. You are here (stytch-python).
  2. The Stytch API can sign with a new key type when a project opts in. Projects that do not opt in see no change.
  3. The SDKs verify tokens that are signed with the new key type.

Test plan

Tests added; all tests passing.

Session authenticate_jwt (B2C and B2B, sync and async) raised PyJWKClientError when the JWT's kid wasn't in the JWKS, or when its key type isn't supported by PyJWT. That error is now handled the same way as an expired JWT: local verification returns None and the SDK calls the Authenticate API.

M2M and Connected Apps local verification are unchanged.

Bumps the version to 15.3.1.
@evan-twilio
evan-twilio marked this pull request as ready for review December 3, 2026 03:15
@evan-twilio
evan-twilio requested a review from a team as a code owner December 3, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant