Skip to content

refactor: share the auth callback parameters and secure random helpers - #1744

Merged
spydon merged 1 commit into
mainfrom
sdk-1281-shared-production-helpers
Aug 20, 2026
Merged

spydon merged 1 commit into
mainfrom
sdk-1281-shared-production-helpers

Conversation

@spydon

@spydon spydon commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1572 (SDK-1281): a duplication sweep after the extraction tiers landed surfaced a few remaining production-code items.

Changes

  • Shared auth callback parameter vocabulary. The sb_flow_id literal was hardcoded in supabase_flutter because AuthConstants is internal to supabase_auth, and the set of auth callback URL parameters was listed independently in supabase_auth and supabase_flutter. Both now come from supabase_common (pkceFlowIdParam, authCallbackParameters), so the package that reads the parameters and the package that strips them from a callback URL cannot drift apart.
  • Shared secure random helpers. randomBytes and randomHex in supabase_common replace four hand-rolled "generate N secure random bytes and encode them" sites: the PKCE verifier generation, the PKCE flow id generation, generateRawNonce in supabase_flutter (public API unchanged, only the body moved), and the UUIDv7 idempotency key in iceberg.
  • iceberg uses the shared isSuccessStatusCode instead of an inlined status range check, the last local status check in the repo.
  • postgrest uses the shared sendWith transport helper instead of hand-rolling the "create a one-off client when none is injected and close it afterwards" dance that storage, functions, and iceberg already get from supabase_common.

No public API changes; AuthConstants.pkceFlowIdParam was @internal.

Testing

  • dart analyze clean on all touched packages
  • Full test suites of supabase_common, iceberg, postgrest, supabase_auth, supabase, and supabase_flutter pass against the local CLI stack
  • Compliance symbol and drift checks pass locally

Summary by CodeRabbit

  • New Features

    • Added shared secure random-generation utilities for authentication flows.
    • Standardized authentication callback parameter handling across packages.
    • Improved PKCE redirect flow tracking and verifier identification.
  • Bug Fixes

    • Improved HTTP success-status detection and request cancellation handling.
    • Strengthened entropy generation for idempotency keys, PKCE verifiers, and nonces.
    • Reduced the risk of authentication callback parameters becoming inconsistent across components.

Centralizes the auth callback URL parameter vocabulary (including the
reserved sb_flow_id parameter) in supabase_common so the packages that
read the parameters and the package that strips them from a callback
URL cannot drift apart. Adds shared randomBytes and randomHex helpers
and uses them in the PKCE verifier generation, the PKCE flow id
generation, the raw nonce generation, and the iceberg idempotency key.
Also switches iceberg to the shared isSuccessStatusCode and postgrest
to the shared sendWith transport helper.
@spydon
spydon requested a review from a team as a code owner August 20, 2026 09:47
@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c1df2983-25b5-40c5-b336-0bb35ca5f137

📥 Commits

Reviewing files that changed from the base of the PR and between dd61782 and 99cc0c0.

📒 Files selected for processing (13)
  • packages/iceberg/lib/src/iceberg_rest_catalog.dart
  • packages/postgrest/lib/src/postgrest_builder.dart
  • packages/supabase_auth/lib/src/auth_client.dart
  • packages/supabase_auth/lib/src/auth_constants.dart
  • packages/supabase_auth/lib/src/helper.dart
  • packages/supabase_auth/lib/src/pkce_verifier_store.dart
  • packages/supabase_auth/test/pkce_flow_test.dart
  • packages/supabase_common/lib/src/auth_callback.dart
  • packages/supabase_common/lib/src/pkce.dart
  • packages/supabase_common/lib/src/random.dart
  • packages/supabase_common/lib/supabase_common.dart
  • packages/supabase_flutter/lib/src/clear_auth_url_parameters.dart
  • packages/supabase_flutter/lib/src/supabase_auth.dart
💤 Files with no reviewable changes (1)
  • packages/supabase_auth/lib/src/auth_constants.dart

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds shared callback and secure-random utilities. Authentication, Flutter, and Iceberg adopt them. PostgREST sends abortable requests through its configured client. Iceberg uses shared success-status validation.

Changes

Shared utilities and auth integration

Layer / File(s) Summary
Shared callback and random utility contracts
packages/supabase_common/lib/src/auth_callback.dart, packages/supabase_common/lib/src/random.dart, packages/supabase_common/lib/supabase_common.dart
Adds shared callback parameter constants and secure random helpers. Exports both utilities.
Secure random utility adoption
packages/supabase_common/lib/src/pkce.dart, packages/supabase_auth/lib/src/pkce_verifier_store.dart, packages/supabase_flutter/lib/src/supabase_auth.dart, packages/iceberg/lib/src/iceberg_rest_catalog.dart
Uses shared random byte and hexadecimal generation for PKCE verifiers, flow IDs, nonces, and idempotency keys. Iceberg also uses isSuccessStatusCode.
PKCE callback parameter integration
packages/supabase_auth/lib/src/auth_client.dart, packages/supabase_auth/lib/src/helper.dart, packages/supabase_auth/test/pkce_flow_test.dart, packages/supabase_flutter/lib/src/clear_auth_url_parameters.dart
Uses the shared PKCE flow ID constant and shared callback parameter set in auth flows, URL filtering, and tests.

HTTP execution cleanup

Layer / File(s) Summary
Direct abortable request execution
packages/postgrest/lib/src/postgrest_builder.dart
Sends abortable requests through _httpClient and retains timeout cancellation in the finally block.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 99cc0

This refactor centralizes existing authentication, randomness, status, and transport helpers without public API changes; no actionable merge-blocking risk remains beyond normal checks and review.

Possibly related PRs

Suggested labels: auth

Suggested reviewers: tr00d

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: shared auth callback parameters and secure random helpers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sdk-1281-shared-production-helpers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@spydon
spydon merged commit 66ac490 into main Aug 20, 2026
45 checks passed
@spydon
spydon deleted the sdk-1281-shared-production-helpers branch August 20, 2026 12:07
spydon added a commit that referenced this pull request Aug 31, 2026
…trix (#1787)

## What

The capability-ID sync in #1786 added
`auth.sign_in.concurrent_pkce_flows` to `sdk-compliance.yaml` with the
default `not_implemented` status. The capability is already implemented,
so this marks it `implemented` and gives it the symbols that describe
it.

## Why it is already implemented

The canonical capability asks for each PKCE code verifier to live in its
own bounded, per-flow slot keyed by a generated flow id, with the code
exchange accepting an optional flow id to select the right verifier.
That is what `PKCEVerifierStore` does, landed in #1662 and refactored in
#1744:

- Each flow gets its own storage slot, pending ids are tracked in an
index entry, and starting another flow past
`AuthConstants.pkceMaxConcurrentFlows` (5) evicts the oldest.
- `AuthClient.exchangeCodeForSession` takes an optional `flowId` and
validates it before building a storage key.
- `AuthClient.appendPkceFlowIdToRedirects` and
`AuthClientOptions.appendPkceFlowIdToRedirects` put the id on the
callback URL, and `getOAuthSignInUrl` / `getLinkIdentityUrl` return it
as `OAuthResponse.flowId`.

## Changes

`AuthClient.appendPkceFlowIdToRedirects`,
`AuthClientOptions.appendPkceFlowIdToRedirects` and
`OAuthResponse.flowId` move from
`auth.sign_in.exchange_code_for_session` to the new capability, which is
where they belong now that it exists. `exchange_code_for_session` keeps
`AuthClient.exchangeCodeForSession`.

No note is added, since the implementation matches expected parity.

## Verification

The supabase/sdk compliance tooling was run locally against this branch:

```
validate-compliance  OK — compliance file is valid.
check-api-symbols    All new public API symbols are covered in the capability matrix.
check-drift          No capability matrix drift detected.
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added support for handling multiple concurrent PKCE authentication
flows.
* **Bug Fixes**
* Updated sign-in capability reporting to accurately associate PKCE flow
support with concurrent authentication flows.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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