ai-assisted-todolist

Authentication#

How TaskFest signs people in: the website through the backend, with a session the backend keeps, and the apps with a bearer ID token, or an app session they trade one for (App sessions). The code is serverless/internal/auth, with the sessions' storage in serverless/internal/store/sessions.go. It keeps the paths, providers and rules of the Quarkus backend it replaced, which the tag pre-serverless holds; what differs from it, and why, is in serverless.md.

The shape: backend-for-frontend#

The backend is the OIDC client. It performs the authorization code exchange itself, verifies the ID token it gets, and then keeps nothing of the provider's tokens: the session is an item in DynamoDB holding who signed in, and the browser holds only a cookie with a random value whose SHA-256 is that item's key. The single-page app never obtains, holds or sends a token — it sends a cookie, like any classic web session. (The mobile app cannot, and sends a bearer ID token instead: Apps sign in with a bearer ID token.)

This was chosen over the more common "SPA gets a token, backend validates the bearer" arrangement because tokens in browser storage are the part of that design that goes wrong, and because a browser session is simply less machinery for an app with one origin (decisions/authentication.md).

The flow#

1. Browser  GET /api/auth/providers          → the sign-in options for the signed-out page
2. Browser  GET /api/auth/login              (full-page navigation, not fetch)
3. Backend  stores the sign-in under way, sets taskfest_signin,
            302 → provider /authorize?...state=...&nonce=...&code_challenge=...
                  &redirect_uri=<origin>/api/auth/callback
4. Provider shows its login form; user authenticates
5. Provider 302 → <origin>/api/auth/callback?code=...&state=...
6. Backend  checks the state, exchanges the code with the PKCE verifier, verifies the ID token,
            stores the session, sets taskfest_session, 303 → the post-login redirect
7. Browser  GET /api/auth/me                 → { "email": "...", "name": ..., "pictureUrl": ... }

Steps 2 and 5 are browser navigations. That is why the sign-in control is a link rather than a button with an onClick — a fetch cannot follow a cross-origin redirect into a login form.

Service.Login starts the flow and Service.Callback finishes it (internal/auth/service.go). The callbacks are routed in internal/api/server.go beside the generated routes, since only a provider calls them and the contract leaves them out.

How long a session lasts#

A session ends after eight hours without a request, and in any case seven days after signing in (IdleLifetime, AbsoluteLifetime). It is never renewed with the provider: no refresh token is asked for or kept, so nothing happens when the provider's ID token runs out after its hour. A busy session records its latest request at most every five minutes, which is all an eight-hour limit needs. The item carries expiresAt, the table's TTL attribute, and the backend checks both times on every read as well, since TTL deletes late (serverless.md has the reasons, Gunnar's decisions on #549).

When a session has ended, the frontend notices on whichever request comes first — the backend answers 401 — and shows "Your session has expired" above the sign-in options instead of an error message (SessionExpiredError in frontend/src/api.ts). Signing in again is a full page navigation, so anything typed but not saved is lost; the notice at least says why.

The cookies#

Cookie Holds Lasts
taskfest_session the session's random value, 32 bytes seven days; the server ends it sooner
taskfest_signin the state of a sign-in under way ten minutes, cleared at the callback

Both are HttpOnly, SameSite=Lax and on the path /, and Secure everywhere but where TASKFEST_COOKIE_SECURE=false says the site is plain HTTP, which only the end-to-end stack and running from source do. The table stores only each value's SHA-256, so nothing in it lets anyone in. Signing in or out also expires any q_session… and q_auth… cookie a browser still holds from the Quarkus backend.

One exception: taskfest_signin for a form_post provider is SameSite=None. A browser does not send a Lax cookie with a POST from another site, so with Lax the state check would refuse every sign-in that provider posts back. None is safe for this cookie because it carries no authority: it holds the random state of one sign-in, for ten minutes, and the callback refuses any POST whose state is not the cookie's — a forged one cannot know it, and an attacker's own code and state (login CSRF) do not match the victim's cookie. That comparison is the CSRF defence, and it needs the cookie. None requires Secure, so where cookies are not Secure it stays Lax; a form_post provider needs https anyway. The session cookie stays Lax for every provider (Service.signInCookie; decisions/authentication.md).

Sign-out#

GET /api/auth/logout deletes the session's item, and its link from the user's partition, expires the cookie, and redirects to the post-login redirect (Service.Logout). Since the session lives on the server, a copy of the cookie stops working too.

It is deliberately not an RP-initiated logout, so the identity provider's own session survives: signing out and back in will not prompt for credentials again. This matters for tests — the Playwright suite opens a fresh browser.newContext() per account, because reusing one would silently sign the second account in as the first.

Deleting the account ends its sessions on every device, the apps' sessions among them, through the links each sign-in writes into the user's partition (serverless.md). The apps sign out with DELETE /api/auth/app-session (App sessions).

Which provider, where#

Every deployment with sign-in has a main provider, which signs in at /api/auth/login, and may have further providers beside it (#143) — qa gets a Cognito pool with test accounts that automated tests can sign in with (#190), since Google forbids automating its own sign-in. The main provider is the first in TASKFEST_AUTH_PROVIDERS.

Where Providers Credentials
prod google, and apple beside it (#642) Google's: the client id from terraform.tfvars; the secret from Secrets Manager, named by TASKFEST_OIDC_GOOGLE_CLIENT_SECRET_ARN and read once per cold start (internal/secrets) (deployment/names-and-certificates.md)
qa google, and cognito beside it (test_sign_in = true) Google's as in prod; the test accounts' pool and client are made by deployment/aws-tofu/modules/environment/test-sign-in.tf; serverless.tf puts the client's id and secret in the function's settings
the end-to-end stack, and running from source keycloak taskfest-backend / taskfest-secret, checked in as throwaway values

Apple's, in prod, where apple_sign_in is offered (#281, #642): the Services ID, key id and team id from terraform.tfvars, the key from Secrets Manager (deployment/names-and-certificates.md). qa never offers Apple: Apple keeps no list of test users, and qa is for invited testers (#607).

deployment/aws-tofu/modules/environment/serverless.tf writes these settings. An environment with no Google client id has sign-in switched off: TASKFEST_AUTH_ENABLED is false and no provider is declared.

The settings#

Every provider is configuration, no code (auth.LoadConfig in internal/auth/config.go):

TASKFEST_AUTH_ENABLED=true               # off: providers are listed, none is usable
TASKFEST_AUTH_PROVIDERS=google,cognito   # the ids, the main provider first
TASKFEST_OIDC_<ID>_LABEL=…               # the button; the id when left out
TASKFEST_OIDC_<ID>_ISSUER=…              # exactly as the ID tokens' iss spells it
TASKFEST_OIDC_<ID>_DISCOVERY_URL=…       # where its metadata is, when not at the issuer
TASKFEST_OIDC_<ID>_CLIENT_ID=…
TASKFEST_OIDC_<ID>_CLIENT_SECRET=…       # or _CLIENT_SECRET_ARN, a Secrets Manager secret
TASKFEST_OIDC_<ID>_AUDIENCES=…           # further client ids a bearer token may be issued to
TASKFEST_OIDC_<ID>_SCOPES=openid,email   # what sign-in asks for; openid,email,profile if unset
TASKFEST_OIDC_<ID>_RESPONSE_MODE=form_post  # the provider POSTs the browser back; query if unset
TASKFEST_OIDC_<ID>_PKCE=false            # leaves PKCE out with this provider; on if unset
TASKFEST_OIDC_<ID>_SIGNING_KEY_SECRET=…  # instead of CLIENT_SECRET: a PEM EC P-256 key that signs
                                         # it, or _SIGNING_KEY_SECRET_ARN, a Secrets Manager secret
TASKFEST_OIDC_<ID>_SIGNING_KEY_ID=…      # the key's id, the signed secret's kid
TASKFEST_OIDC_<ID>_SIGNING_TEAM_ID=…     # the signed secret's iss

<ID> is the id in upper case, with - as _.

Sign in with Apple#

Apple (#281) is a further provider like any other, configured, not coded; what sets it apart is three settings no other provider needs. Its website client is a Services ID, whose return URL is <public origin>/api/auth/callback/<id>:

TASKFEST_OIDC_APPLE_ISSUER=https://appleid.apple.com
TASKFEST_OIDC_APPLE_CLIENT_ID=<the Services ID>
TASKFEST_OIDC_APPLE_SIGNING_KEY_SECRET_ARN=<the secret holding the .p8 file's text>
TASKFEST_OIDC_APPLE_SIGNING_KEY_ID=<the key's 10-character id>
TASKFEST_OIDC_APPLE_SIGNING_TEAM_ID=<the 10-character team id>
TASKFEST_OIDC_APPLE_SCOPES=openid,email
TASKFEST_OIDC_APPLE_RESPONSE_MODE=form_post

Every provider must vouch for the email#

The email is the identity: with more than one provider, the same address from either means the same person. So a sign-in is refused unless the provider says the address is verified (email_verified in the ID token) — otherwise a provider that hands out unchecked addresses could sign someone in as another person's account. verifyIDToken in internal/auth/tokens.go enforces it for every provider, at the callback and for bearer tokens alike, and refuses a token without an email. The claim is the boolean true at Google and Keycloak; Cognito has sent the string "true", and Apple documents either, which is accepted too, in any case. Adding a provider therefore means trusting it with that claim — see decisions/authentication.md.

Apps sign in with a bearer ID token#

The mobile app (#264) cannot use the cookie: Google refuses sign-in inside a WebView, and a cookie set in the system browser never reaches the app. It signs in with its platform's own sign-in — Google's SDK, Apple's on iOS, or code + PKCE through the system browser — and sends the ID token it is given as Authorization: Bearer (decisions/mobile-app.md). Since #281 it sends it once, to trade it for an app session, whose token it sends on every request from then on (App sessions). An ID token is still accepted on any request: from an app older than app sessions (before v1.8.0), and from any other client that sends one. This section is how it is checked, wherever it is sent.

App      sign-in with the platform's SDK          → an ID token
App      POST /api/auth/app-session  Authorization: Bearer <ID token>
           (an app from before app sessions: GET /api/tasks and the rest with it)
Backend  provider by the token's iss → signature, issuer, expiry (go-oidc)
         → issued to one of the provider's clients? an ID token? email verified? (verifyIDToken)
         → 201 or 200, or 401 — never a redirect, never a session cookie

App sessions#

Apple's native sign-in on iOS (#281) gives the app an ID token that it cannot renew without the person, unlike Google's SDK. So, after every sign-in, whatever the provider, the app trades its ID token once for an app session of the backend's own, and sends that session's token from then on; the backend keeps no provider's refresh token (decisions/authentication.md).

App      native sign-in                               → the provider's ID token
App      POST /api/auth/app-session  Authorization: Bearer <ID token>
Backend  the ID token checked as any bearer ID token (above) → the session stored
         → 201 { "token": "taskfest_app_…", "expiresAt": "2026-12-16T09:30:00Z" }
App      keeps the token in the Keychain / Keystore
App      GET /api/tasks  Authorization: Bearer taskfest_app_…  → 200, or 401 once it has ended
App      DELETE /api/auth/app-session  Authorization: Bearer taskfest_app_…  → 204 (sign-out)

The provider list#

GET /api/auth/providers drives the signed-out screen (Config.List, ordered by id). A provider is advertised as usable purely because configuration gave it a client id and secret:

Available: c.Enabled && p.Usable() // a client id and a secret, neither blank

No provider name appears in the code, on either side. Adding one is a configuration change: its id joins TASKFEST_AUTH_PROVIDERS, its TASKFEST_OIDC_<ID>_* settings are set, and a sign-in button appears with it. The end-to-end stack and running from source declare keycloak; AWS declares google, and cognito in qa alone. A provider not declared is not part of the deployment at all: it is left out of the list and its paths are a 404 — so prod's list holds Google alone.

A declared provider without credentials is still reported, with available: false and a null loginUrl — but the frontend hides it rather than showing it disabled (SignedOut.tsx), and says sign-in is not configured when nothing is left. The endpoint reports it anyway so that a caller can tell a provider that exists but is unconfigured from one that was never declared; see decisions/frontend.md. In AWS a Google client secret that cannot be read stops the function's start instead.

Local accounts#

keycloak/realm-taskfest.json is imported by the end-to-end stack's Keycloak, which also backs running the backend from source (local-development), so the same realm backs local runs and CI. It has two clients: taskfest-backend, the backend's, and taskfest-app, the mobile app's public one.

Account Password Email
gunnar gunnar gunnar@example.com
lasse lasse lasse@example.com

The email claim is not optional decoration — it is the identity, so a token without one is refused. See domain-model.md.

These credentials are testing-only placeholders and belong in the repository. Real secrets never do.

What the browser learns about you#

GET /api/auth/me answers with three fields, and only the first is identity:

Field Where it comes from Absent when
email the email claim never — a token without one is refused
name the name claim the provider supplied none
pictureUrl the picture claim, else a Gravatar the backend has confirmed exists neither is available

An absent field is null.

The name and picture are not part of the account. Nothing stores them with the user's tasks: the website's session item keeps them, with the email, for as long as the session lasts, and a bearer request reads them from its token each time. The email remains the whole of the identity, which is what a user's partition is keyed by and what ownership is decided on: USER#<SHA-256 of the email lower-cased>, so Gunnar@Example.com and gunnar@example.com are one account whichever case a provider sends (#622). An account begun before that under an email with capitals was keyed by the email as sent, and keeps that partition: Accounts.AccountEmail (internal/store/emails.go) answers which email keys the account, with one read of that partition's META item for an email with capitals and none for one in lower case. Such a board is found only under exactly that casing: signed in as gunnar@example.com, or as any other casing, the lower-cased account is used, and the two stay apart until the older one is deleted. The API's caller is that email (api.Keyed), and so are a session's link, an account's deletion and its deletion record. A consequence worth knowing: because nothing outlives the session, a name can only ever be shown to its own owner. Anything that had to display one user's name to another — sharing, an audit trail — would have to revisit that (decisions/authentication.md).

Both need the profile scope, which every sign-in asks for but Apple's, which knows none and sends neither (Sign in with Apple). These are non-sensitive scopes; Google needs no verification review for them, and picture arrives with profile rather than being a permission of its own.

The Gravatar fallback#

Consulted only when the provider sent no picture, and only by /api/auth/me, never by the callback or another request (Service.WithPicture, internal/gravatar). Google almost always sends one; Keycloak here never does.

The backend makes the request rather than the browser, so that "if an image is available" is actually answered — ?d=404 is what makes Gravatar say no instead of inventing a picture. This does not make the browser's request go away: the page still loads the image from gravatar.com, so a third party still sees the reader's address and a hash of their email. What the server-side check buys is a truthful answer, not privacy. decisions/authentication.md records that rather than leaving it implied.

Two things stop it becoming a liability on the sign-in path. The answer, picture or none, is remembered by address for the life of the execution environment, because /api/auth/me runs on every page load and would otherwise mean an outbound request on every page load. And failure is not an error: a slow or unreachable Gravatar, which gets two seconds, yields no picture and is asked again next time, and sign-in carries on. Nobody should be locked out of their tasks because an avatar service is having a bad day.

TASKFEST_GRAVATAR_ENABLED=false switches it off entirely, which is what the end-to-end stack does so that it never reaches the internet.

Settings that are load-bearing#

Three settings look innocuous and are not; each of them, wrong, sends sign-in somewhere else.

What is tested#

The Go tests run against fakeProvider (internal/auth/provider_test.go), an OpenID Connect provider in the test with its own keys, discovery and token endpoint.

See testing.md.