Skip to content

fix(verify): confirm magic links with the code from the link's fragment - #378

Open
Bccorb wants to merge 1 commit into
mainfrom
fix/verify-magic-link-confirm
Open

Bccorb wants to merge 1 commit into
mainfrom
fix/verify-magic-link-confirm

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Part of fells-code/seamless-auth-api#603. Follows fells-code/seamless-auth-api#614 (M6, fells-code/seamless-auth-api#594), which broke the verify job in every repo that runs this suite.

What changes

The suite moves to the magic link contract from api#614:

  • The link is <target>?token=T#code=C.
  • GET /magic-link/verify/:token never signs in. It answers 409 confirmation_required with sameDevice.
  • Only POST /magic-link/verify/:token/confirm with { code } consumes the link.

Harness flows

  • lib/flows.ts: parseMagicLink splits the delivered magicLinkUrl into token and code. It also asserts that the code is in the fragment and not in the query. requestMagicLink returns both, and confirmMagicLink is new. verifyMagicLink optionally sends the ephemeral bearer.
  • lib/adapterFlows.ts: loginViaMagicLink reads the link from /__captured and expects the 409 with sameDevice: true. It then confirms with the code through the adapter and polls for the session.

New assertions

  • API:
    • The requesting attempt gets the 409 with sameDevice: true, and the link stays unconsumed after a verify.
    • A link with its fragment stripped cannot sign in: a confirm with no code is a 400, and the poll stays 204.
    • A wrong code is a 400 and spends the link, so the right code, and a later verify, are refused.
  • Adapter (Express and Fastify): a confirm with no code through the adapter is refused, and no session is issued.

Browser specs

react/magicLinkLogin.spec.ts and nextjs/magicLinkLogin.spec.ts open the full captured link, fragment included. Each verify must answer 409, and each confirm must succeed with at least one sent. Under Strict Mode, a screen that confirms twice spends the link on the first confirm and fails the second, so the double confirm is caught. The React spec also checks that the screen strips the code from the address bar.

Reference apps

The Angular, Vue and Svelte apps pin @seamless-auth/angular 0.6.0, @seamless-auth/vue 0.5.0 and @seamless-auth/svelte 0.5.0. Before, the Dockerfiles defaulted to latest, and the CI build cache keys that layer on its command and build args, so latest kept serving the release it first resolved. The React and Next.js apps come from seamless-templates, and fells-code/seamless-templates#175 moves them to client 0.11.0, react 0.21.0 and nextjs 0.11.0.

Docs and release

verify/CONFORMANCE.md describes the new contract. The changeset is patch, matching the earlier harness contract changes (#345, #353, #374).

Local runs

Each run used API main (45530a8) and a fresh SEAMLESS_RUN_ID. Ports 3000 and 5312 are held by another stack on the machine, so a scratch compose override moved the auth API to 5313 and the Express adapter to 3002.

  • --local --dev, templates main:
    • Passed: API/adapter (apart from one spec of mine, fixed since), all React layers, and the Angular, Vue and Svelte production builds.
    • Next.js failed as expected: the starter on templates main does not read the code.
    • Failed for the environment: the Angular, Vue and Svelte dev layers. Their dev servers hard-code http://localhost:3000 for the adapter, so they reached the other stack on the machine and not the verify adapter.
  • --dev (published SDKs), templates#175: 10 of 13 layers pass, including API/adapter, react-vite, react-oauth, and Next.js on both build and dev. The other 3 are the same Angular, Vue and Svelte dev layers, which fail for the port reason above.

This PR's own conformance job runs the dev layers on clean ports.

Callers to re-pin after release

verify-conformance.yml checks out this repo at inputs.cli-ref. Callers that leave it empty get the harness from main, so their matrix job is fixed when this merges. They still pin the workflow file itself:

  • seamless-auth-server .github/workflows/conformance.yml:
    • The workflow is pinned at v0.30.3 (ab96e73).
    • The separate nextjs job checks out this repo at v0.30.3 explicitly, so its specs stay on the old contract until it is re-pinned.
  • seamless-auth-api .github/workflows/conformance.yml: workflow pinned at v0.27.2 (28a363f).
  • seamless-templates .github/workflows/conformance.yml: workflow pinned at v0.26.0 (1ff9552).
  • These follow main and need no change:
    • seamless-auth-js, whose conformance workflow uses @main.
    • seamless-auth-go, seamless-auth-python and seamless-auth-rust, whose CI checks out this repo with no ref.

seamless-auth-api#614 stops GET /magic-link/verify/:token from signing in. It always answers 409 confirmation_required with sameDevice, and only a confirm carrying the code from the link's #code= fragment consumes the link. The api, adapter and browser specs now take the code from the delivered link and confirm with it, and new specs cover a missing code, a wrong code and the adapter forwarding the confirm body.

The Angular, Vue and Svelte reference apps pin their SDK releases instead of latest, which the CI build cache would otherwise keep at an older release.
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.

1 participant