Skip to content

Connect the browser extension by pasting a device key #82

Closed

Description

@Divy97

Problem Statement

Connecting the browser extension today goes through a web-auth-flow approval page. It only works when the browser profile running the extension can complete a sign-in in that flow, it needs the extension's exact ID allow-listed in the Worker's configuration (a deploy per new ID), it cannot work on Firefox where every install gets a random ID, and it needs an extra browser permission. The owner wants the extension in many browser profiles and browsers without redeploying the API each time, and the first attempt at the flow also failed silently because the popup was torn down mid-flow.

Solution

The User creates a device key in Settings, copies it once, and pastes it into the extension popup. The extension checks the key against the API's connection check and, if valid, stores it and shows as connected. Works in any browser or profile, with no approval page, no redirect allow-list and no extra permission. Device listing and revoking in Settings stay as they are. The web-auth-flow connect path is removed rather than carried alongside.

User Stories

  1. As a User, I want a "Create device key" button in Settings, so that I can connect an extension without it needing my credentials.
  2. As a User, I want to name a device key when I create it (defaulting to a sensible label), so that I can tell my browsers apart in the device list.
  3. As a User, I want the full key shown once at creation with a copy button, so that I can paste it into the extension.
  4. As a User, I want a clear warning that the key will not be shown again, so that I do not close the dialog before copying it.
  5. As a User, I want the new device to appear in Connected Devices straight after creation, so that I can see it was made.
  6. As a User, I want to revoke any device key from Settings, so that a lost or leaked key stops working on the next request.
  7. As a User, I want a pasted key to be checked before the extension says it is connected, so that a typo does not leave me in a broken state.
  8. As a User, I want a specific message for an invalid, revoked or malformed key, so that I know whether to create a new one.
  9. As a User, I want a specific message when the API cannot be reached, so that I do not mistake a network problem for a bad key.
  10. As a User, I want the popup to show the account email once connected, so that I know which Second Brain it is attached to.
  11. As a User, I want to use the same extension in several browser profiles and browsers, each with its own key, so that revoking one does not break the others.
  12. As a User, I want to connect Firefox and Brave the same way as Chrome, so that I am not limited by which browser APIs exist.
  13. As a User, I want to disconnect from inside the extension, so that I can sign out without opening the web app.
  14. As a User, I want a revoked key to turn the popup back to the connect screen with a "reconnect" message, so that a revoked device does not fail silently.
  15. As a User, I want the key field to be a password-style input and cleared after success, so that the key is not left visible on screen.
  16. As a User, I want the connect screen to tell me where to create a key (link to Settings), so that I am not left guessing.
  17. As a User, I want the popup to stay open and show progress while the key is checked, so that clicking Connect never appears to do nothing.
  18. As a User, I want device keys to carry only the narrow extension permissions, so that a leaked key cannot read my notes, ask questions or touch my API keys.
  19. As a User, I want a device key to be rejected on every session-only route, so that a leaked key cannot be used on the rest of the app.
  20. As a User, I want a cap on how many device keys I can hold, so that a script cannot fill my account with keys.
  21. As the operator, I want connecting a new extension install to need no API deploy or configuration change, so that publishing under a new ID costs nothing.
  22. As the operator, I want the old connect routes, approval page, redirect allow-list and identity permission removed, so that there is one connect path to secure and maintain.
  23. As the operator, I want the key minted only by our own authenticated route with the fixed permission set, so that the stock create route stays disabled.

Implementation Decisions

  • Supersedes the pasted-token rejection in ADR-0007. A new ADR records the reversal: why (multi-profile, Firefox random IDs, redirect allow-list deploys, web-auth-flow fragility) and the accepted cost (the key transits the clipboard and may appear in screenshots; mitigated by show-once, revoke-only, narrow permissions, and key-prefix scanning friendliness). ADR-0007's other decisions (device tokens from the API Key plugin, the separate extension router, extension CORS, hashing at rest) stand.
  • New authenticated session route for minting a device key: takes an optional label, creates a key through the API Key plugin with the fixed extension permission set and the existing key prefix, returns the full key exactly once alongside the device record. Rate limited per User and capped at a maximum number of active device keys.
  • Label defaults server-side when omitted so the list is never blank.
  • Remove: the authorization-code create and token-exchange routes, their storage (authorization codes table and queries), the code/PKCE crypto helpers, the redirect allow-list configuration variable, the web approval page and its layout, and the extension's PKCE and web-auth-flow code, message hand-off to the background worker, and identity permission. Drop the authorization codes table with a migration.
  • Extension CORS and the extension router are unchanged except the removed token-exchange path leaves the extension-path check.
  • Connection check route is unchanged and is what the popup calls to validate a pasted key. It returns the account email and device label; a 401 means invalid or revoked.
  • Extension popup: connect screen gets a password-style key field and a Connect button. On Connect it validates against the connection check, stores the key in extension local storage only on success, and shows distinct states for checking, invalid key, revoked key and unreachable API. Connected screen is unchanged apart from disconnect clearing the stored key.
  • Web Settings: Connected Devices section gets a "Create device key" action. It opens a dialog with an optional label, then shows the key once with a copy control and a not-shown-again warning, and refreshes the device list when closed.
  • Keep from the in-progress work: context menu registered only on install, and the committed production-origin env file for the extension build.
  • Update the existing browser-extension spec's connect user stories and "Connect flow" paragraph to match, so the two documents do not disagree.

Testing Decisions

  • A good test drives external behaviour only: HTTP requests and responses, what the user sees and does, what the popup renders. No asserting on internal helpers.
  • Seam 1, API HTTP (primary), in the existing Workers test pool. Prior art: the extension auth, CORS, capture and keys tests. Covers: mint requires a session; minted key is returned once and is accepted by the connection check; key carries exactly the extension permissions; label default and custom label; key rejected on session-only routes; session cookie rejected on the extension router; revoke makes the key fail on the next request; per-User cap; stock create route still disabled; removed connect routes no longer exist.
  • Seam 2, web Playwright e2e, extending the existing device settings spec. Covers: Create device key shows the key once with a copy control and warning, closing refreshes the list with the new device, and the key is not retrievable afterwards.
  • Seam 3, extension Vitest with WXT's in-memory browser API. Prior art: the existing queue test. Covers: valid key is stored and email shown; 401 shows an invalid/revoked message and stores nothing; network failure shows an unreachable message and stores nothing; disconnect clears the key; a 401 during normal use returns the popup to the connect screen.
  • Verification per the repo workflow (UI in a browser) is the User's own check for this work; tests above carry the automated proof.

Out of Scope

  • One-click connect (web-auth-flow or pinned extension key). Can return later if paste friction hurts.
  • Key expiry and rotation (still revoke-only).
  • Editing or renaming a device after creation.
  • Changing the extension's permission set or any captured-data behaviour.
  • Chrome Web Store / AMO publishing and the extension icon set.
  • Automating the Worker deploy and database migration steps.

Further Notes

  • The earlier work on a branch-less working tree (identity permission, background hand-off, redirect URI in wrangler config) should be dropped except the context-menu fix and the production env file; implement on a fresh fix//feat/ branch from master.
  • The Settings "Connected Devices" and "Capture Settings" 404/500 seen earlier were deploy and migration gaps, not code bugs; the same two manual steps (Worker deploy, db:migrate) are needed for this change, including the migration that drops the authorization codes table.

Activity

  1. added
    ready-for-agent
    on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions