This is Supabase acting as the OAuth server#
Hosted Coconut uses authorization-code flow with PKCE against the shared Supabase Auth OAuth server. This is not “Sign in with GitHub,” and it does not forward the central portal's password session token to a subdomain.
The reviewed public registration is:
| Setting | Value |
|---|---|
| Client ID | 978d0b67-d40a-4cd2-a686-b0e4f9ab4d22 |
| Client type | Public |
| Token endpoint authentication | none |
| Exact callback | https://coconut.seedworkslab.de/auth/callback |
| Requested scope | email |
| Consent UI | https://seedworkslab.de/oauth/consent.html |
| Dynamic registration | Disabled |
A public client has no browser-held client secret. The email scope does not independently constrain database access to an email address; the server-side app boundary is essential.
Sequence#
Coconut tab Supabase Auth Central website
│ create state + verifier
│ derive S256 challenge
├── /oauth/authorize ───>│
│ ├── consent authorization_id ─>│
│ │ │ verify central user
│ │ │ require backend ready
│ │<── details / approve / deny ─┤
│<── callback code + state (or validated error) ────────┤
│ consume local transaction, remove URL parameters
├── /oauth/token: code + verifier ─>│
│<── delegated tokens ──────────────┤
├── /user with exact access token ─>│
│ validate returned identity + expected claims
│ install app session and open account-bound cache
Initiating the request#
startHostedLogin runs only on the exact Coconut production origin and outside a frame.
It generates independent cryptographically random 32-byte verifier and state values, base64url-encodes them, and computes a SHA-256 PKCE challenge. The verifier, state and creation timestamp go into the initiating tab's session storage.
The authorization URL specifies response type code, the registered client/callback, S256, challenge, state and email. State binds the callback to the initiating transaction; the PKCE verifier prevents an intercepted code from being exchanged by a party missing that tab's secret.
This production-origin restriction means localhost UI preview is not a full production SSO test. Staging needs a separately registered client/callback and explicit matching frontend/backend authorization.
Consent request validation#
oauth-core.js validates the authorization ID's bounded path-safe syntax; Auth still verifies the request's ownership, expiry and meaning.
oauth-consent.js rejects the wrong central origin, framing, missing/duplicated authorization ID and URL fragments. It creates a central client using the account portal's same-origin auth storage.
If no verified user is available, it offers a central sign-in link preserving the authorization ID. Once signed in it calls seed_oauth_sso_ready() and refuses to continue unless the backend reports the isolation boundary is ready.
getAuthorizationDetails retrieves trusted request details. validateConsent requires the exact authorization ID, Coconut client ID, callback, current user ID and exact email scope. It is an allowlist, not a dynamic consent renderer for arbitrary clients.
Approval, denial and previously granted requests#
Before deciding, the page re-verifies the current user and reloads request details. This prevents approving after a different account has replaced the initial session.
Approval calls approveAuthorization; denial calls denyAuthorization, both with automatic browser redirection disabled. The UI validates the returned destination before location.replace.
Some already-granted requests return a redirect immediately. They still pass destination validation. The redirect must:
- Match the exact registered callback origin/path.
- Contain no username/password or fragment.
- Use only approved query keys, with no duplicates.
- Have a 43-character base64url state.
- Include a code or an error, but not both.
Auth sign-out or switching to another user hides the pending request. Restoring the consent page from browser back/forward cache forces a reload rather than relying on stale displayed identity.
Consuming the callback#
completeHostedLogin operates on /auth/callback and deduplicates concurrent invocations. It removes code/error parameters from browser history before network exchange.
It consumes the stored transaction once and checks:
- Exact origin, no fragment, no frame.
- No duplicated query parameters.
- Matching state.
- Expected verifier/state formats.
- Creation timestamp not in the future and no more than ten minutes old.
- No error and a bounded nonempty authorization code.
A replay or a callback opened in a different tab without the transaction fails. The user must restart login; weakening the validation is not an appropriate workaround.
Token exchange and verification#
requestOAuthTokens posts form-encoded fields to /auth/v1/oauth/token, including the public client ID. It omits browser credentials, disables caching/redirect following and bounds the request time.
On success it checks the token response structure, then sends the exact returned access token to the trusted /auth/v1/user endpoint. Only after that verification does validateOAuthClaims inspect:
- Issuer equals the project's
/auth/v1. - Audience and role are
authenticated. - Client ID is the registered Coconut client.
- Subject is nonempty and equals the verified user ID.
- Expiry is finite and in the future.
Decoding a JWT alone is never signature verification. The trusted Auth call is why the later claim checks are meaningful.
The verified response is adapted to the SDK's expected session shape, and auth.setSession installs it in the app-owned client before returning to the app root.
Refresh ownership#
hosted-account-client.web.ts maintains the single SDK client. createOAuthFetch intercepts the SDK's normal refresh request and redirects OAuth refresh work through /oauth/token with the public client ID.
This keeps SDK storage locking, refresh rotation and auth events while avoiding incorrectly treating delegated refresh tokens as ordinary password-session tokens. Successful refresh responses go through the same token/user verification path.
Do not create a second independently refreshing hosted client as a convenience helper; competing refresh owners can cause rotation races and stale session state.
Origin isolation and logout#
The central portal and Coconut subdomain own separate browser storage and sessions. They must not use shared-domain token cookies or copy tokens through query strings/local storage bridges.
The same storage key string on two origins does not share its values. Central logout is not global app logout. Revoking a grant blocks future refresh, not necessarily a still-valid issued JWT, and does not encrypt or remotely wipe the local financial cache.
Safe rollout and acceptance#
Deploy/test the OAuth boundary migration and loaded PostgREST guard before enabling consent and hosted login. Redeploy account deletion so OAuth tokens cannot invoke it. Hosted Supabase settings do not automatically read local config.toml.
Test login with/without an existing central session, approval, denial, callback replay, expiry, reload, refresh rotation, grant revocation, account switching and actual cross-app API denials. SQL policy tests and mocked frontend tests are necessary but do not replace real staging HTTP/browser acceptance.
Authoritative companion: Coconut/docs/hosted-web.md.