Repository navigation
Conversation
GoTrue's implicit grant redirect puts access_token, refresh_token and error parameters in the URL fragment, but initialize_from_url() only parsed the query string, so real callback URLs were never recognised. Parse both the fragment and the query, with the query taking precedence, matching supabase-js. Closes supabase#1664
spydon
added a commit
that referenced
this pull request
Nov 3, 2026
Fixes SDK-2670. Reopens the fix for SDK-1954 / #1664. ## Problem `initialize(url=...)` and `initialize_from_url()` only read `urlparse(url).query`. The implicit grant redirect from Supabase Auth puts its parameters in the fragment (`#access_token=...&refresh_token=...`, or `#error=...&error_description=...` on failure). If you passed in the real callback URL, nothing happened: you got no session, no `SIGNED_IN` event and no error. ## Fix A new private `_parse_url_params()` helper in `helpers.py` merges the fragment and query parameters, and the query wins on conflicts. This matches `parseParametersFromURL` in auth-js. `_is_implicit_grant_flow()` and `_get_session_from_url()` both use it now. A PKCE callback (`?code=...`) has no `access_token` or `error_description`, so it is still not treated as an implicit grant. ## Relation to #1665 #1665 made the same change and was closed without being merged. It had no review, no comments and no stated reason. Because of that, #1664 and SDK-1954 were marked done while the bug is still on `main`. This PR applies the same approach and adds wider test coverage. ## Tests New tests in `tests/_async/test_initialize_from_url.py` (and the generated sync version) mock HTTP with `httpx.MockTransport`, so they need no infra: - Tokens in the fragment produce a session and `SIGNED_IN`. - `type=recovery` in the fragment also fires `PASSWORD_RECOVERY`. - A fragment error redirect raises `AuthImplicitGrantRedirectError` with its details. - Query parameters win over fragment parameters. - Query-only URLs keep working. - A PKCE `?code=` callback is not treated as an implicit grant. The four fragment tests fail on `main` and pass with this change. mypy is clean.
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.
Closes #1664
What
initialize_from_url()/initialize(url=...)only parsed the URL query string, but GoTrue's implicit grant redirect putsaccess_token,refresh_token, and error params in the fragment (#access_token=...). Real callback URLs were never recognised, so no session was saved and noSIGNED_INevent fired.Fix
A new
parse_url_params()helper inhelpers.pymerges fragment and query params, with the query taking precedence (the same as supabase-jsparseParametersFromURL)._is_implicit_grant_flowand_get_session_from_urluse it in both the async and sync clients. Query-only URLs behave as before.Tests
test_initialize_from_url_reads_tokens_from_fragment(async + sync). It fails onmain(get_usercalled 0 times) and passes with the fix.pytestinsrc/authagainst the docker compose infra: 166 passed.mypy src/supabase_auth tests,ruff check,ruff format --check,git diff --check: clean.