This repository was archived by the owner on Aug 7, 2026. It is now read-only.
Repository navigation
fix: classify refresh token rejections from current gotrue - #131
Merged
Merged
Conversation
Since the v2 refresh token algorithm (supabase/auth#2216), gotrue validates the token format before the database lookup and rejects malformed tokens with "Refresh token is not valid" (validation_failed) instead of "Invalid Refresh Token" (refresh_token_not_found). DetectReason only matched the lookup-path message, so these rejections were classified Unknown and RefreshSession kept the dead session instead of destroying it. Match both paths, including the stable refresh_token_not_found error code.
The overload already exists on Client but was missing from the interface, so consumers working against IGotrueClient could not refresh a persisted session without downcasting.
Split refresh coverage into two layers: RefreshContractTests pins the HTTP contract against a WireMock server (request shape, session mapping, error classification for both rejection paths), and RefreshBehaviorTests runs against the local Supabase CLI stack (rotation, expired sessions, malformed and unknown tokens destroying the session). Shared fixtures live in GotrueTests/Support: a client factory per tier and a WireMock wrapper with fluent request assertions.
The bogus and expired token tests in AnonKeyClientFailureTests and the token-refreshed event test in AnonKeyClientTests are covered by the new suites; the persistence assertion unique to the latter moved into RefreshBehaviorTests.
Tr00d
marked this pull request as ready for review
July 7, 2026 09:23
spydon
approved these changes
Jul 7, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Classification fix
Current gotrue (since supabase/auth#2216) validates the refresh token format before the database lookup, so rejections come from two paths with different bodies:
{"error_code":"validation_failed","msg":"Refresh token is not valid"}{"error_code":"refresh_token_not_found","msg":"Invalid Refresh Token: Refresh Token Not Found"}FailureHint.DetectReasononly matched the legacy"Invalid Refresh Token"message, so format rejections were classified asReason.Unknown— and sinceRefreshSession()/RefreshToken()only destroy the session onInvalidRefreshToken, the client kept a dead session asCurrentSession. Both paths are now classified asInvalidRefreshToken, including a match on the stablerefresh_token_not_founderror code since themsgwording has already drifted between server versions.RefreshToken(accessToken, refreshToken)is also now exposed onIGotrueClient. It has beenpubliconClientsince #72 and the same shape exists onIGotrueStatelessClient, but consumers of the umbrellasupabase-csharppackage only seeIGotrueClient, so it was unreachable for them without downcasting. Note: source-breaking for hand-written implementations of the interface (dynamic mocks are unaffected).Test suite improvement
New
GotrueTests/TokenRefresh/suite in two tiers, with shared fixtures inGotrueTests/Support/:RefreshContractTests(WireMock): pins thePOST /token?grant_type=refresh_tokenexchange — request shape, response-to-session mapping, and classification of both rejection bodies.RefreshBehaviorTests(live Supabase CLI stack, gotrue v2.191.0): token rotation, expired-session refresh, and rejected tokens destroying the session. This tier is what surfaced the classification gap: the repo's docker-compose stack pinsgotrue:v2.155.6, which predates format validation and always returns the legacy message. Endpoint and key are overridable viaSUPABASE_CLI_AUTH_URL/SUPABASE_CLI_ANON_KEY.Legacy tests fully superseded by the new suite were removed (
AnonKeyClientFailureTestsbogus/expired token,AnonKeyClientTeststoken-refreshed event); the persistence assertion unique to the latter moved into the new suite.Updating the docker-compose stack to a current gotrue/postgres is deliberately left for a separate PR.
Workflow update
The behavior tier needs a Supabase CLI stack on
127.0.0.1:54321, but CI only started the legacy docker-compose stack (:9999), so those tests failed with connection refused on the runner. The workflow now installs the Supabase CLI and runssupabase startalongside the existing compose stack, backed by a minimalsupabase/config.tomladded to the repo (api, db, and auth only — everything else disabled for startup speed). The CLI's default URL and demo anon key are exactly what the test fixtures expect, so no secrets or environment wiring is required.