Skip to content

Return Error from consumer authenticateJwt when the API rejects the JWT - #156

Merged
logan-twilio merged 2 commits into
mainfrom
logan/consumer-authenticatejwt-error
Oct 20, 2026
Merged

logan-twilio merged 2 commits into
mainfrom
logan/consumer-authenticatejwt-error

Conversation

@logan-twilio

@logan-twilio logan-twilio commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

When local validation fails, consumer authenticateJwt falls back to /v1/sessions/authenticate. If that call returned an error, the method wrapped it as StytchResult.Success:

  • StytchException.Response became Success(JWTErrorResponse(...))
  • any other exception (e.g. an unparseable error body) became Success(JWTNullResponse)

So callers branching on Success vs Error would treat a rejected JWT as authenticated. This now returns the StytchResult.Error unchanged, which is what the B2B authenticateJwt already does.

Changes

  • consumer/api/sessions/Sessions.kt — is StytchResult.Error -> netResult; dropped the now-unused imports
  • common/JWTResponse.kt — deprecated JWTErrorResponse and JWTNullResponse, since nothing returns them anymore. Kept rather than removed so existing code still compiles.
  • consumer/api/sessions/SessionsTest.kt — authenticateJwt tests against a MockWebServer-backed HttpClient: a 401 returns Error(StytchException.Response), and a 500 with an unparseable body returns Error(StytchException.Critical). Both fail on main.
  • Version bump to 11.4.0 (minor, given the behavior change below)

Behavior change

Callers that inspected Success.value is JWTErrorResponse / JWTNullResponse will now get StytchResult.Error instead, and those branches become dead code (flagged by the deprecation warning).

Testing

./gradlew :stytch:test passes (JDK 17).

Open question

This method sits in a MANUAL(authenticateJWT_impl) block, and the interface has ADDIMPORT hints for the deprecated types. Does sdk-codegen also hold this manual block, or need the ADDIMPORT hints updated, so the next regeneration doesn't revert it?

When local JWT validation failed and the remote /sessions/authenticate
call returned an error, consumer authenticateJwt wrapped that error as
StytchResult.Success(JWTErrorResponse) or StytchResult.Success(JWTNullResponse).
Callers branching on Success vs Error would treat a rejected JWT as
authenticated. Pass the StytchResult.Error through unchanged, matching
the B2B implementation.

JWTErrorResponse and JWTNullResponse are no longer returned and are
deprecated.
@logan-twilio
logan-twilio marked this pull request as ready for review October 19, 2026 17:58
@logan-twilio
logan-twilio requested a review from a team as a code owner October 19, 2026 17:58
@logan-twilio
logan-twilio requested review from evan-twilio and removed request for a team October 19, 2026 17:58

@evan-twilio evan-twilio left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logan-twilio
logan-twilio merged commit dd57998 into main Oct 20, 2026
12 checks passed
@logan-twilio
logan-twilio deleted the logan/consumer-authenticatejwt-error branch October 20, 2026 15:47
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.

2 participants