Skip to content

feat: OAuth device flow with QR code - #39

Merged
bergetjakob merged 2 commits into
mainfrom
feat/device-flow
Sep 11, 2026
Merged

bergetjakob merged 2 commits into
mainfrom
feat/device-flow

Conversation

@bergetjakob

Copy link
Copy Markdown
Contributor

Vad

Ny oauth-metod "Berget Code Seat - QR or device code" bredvid magic link, för headless-miljöer (SSH/CI) där PKCE-flödet inte kan öppna en webbläsare lokalt.

Implementation

  • src/plugin/device-flow.ts: RFC 8628 device authorization grant mot Keycloak
    • QR-kod renderad med halvblock-tecken (▀▄█) — enda pålitliga renderingen i opencodes TUI
    • Centrerad layout med ─ or ─-divider mellan QR och fallback-länk
    • url sätts till verification_uri_complete (user_code inbäddat) → opencode visar den highlighted och c kopierar den
    • Polling med slow_down-backoff, expired_token- och timeout-hantering
  • qrcode-dependency tillagd

Testat

  • typecheck, lint, 58 tester gröna
  • Manuellt verifierat i opencode TUI mot både stage (auth.stage.berget.ai) och prod (auth.berget.ai)

Adds a second oauth method 'Berget Code Seat - QR or device code' for
headless environments (SSH/CI) where the PKCE magic link cannot open a
browser. Renders a scannable half-block QR code in the instructions
dialog, links verification_uri_complete (user_code embedded) via the
url field, and polls the token endpoint with slow_down/expiry handling.
Review feedback on #39:
- response.json() in the poll loop could throw on non-JSON bodies
  (e.g. a 502 HTML page from the gateway); extracted fetchTokenPollBody
  which treats transport/parse errors as retryable until the deadline
- add unit tests for extractTokenResult and handleTokenPollError
@bergetjakob
bergetjakob merged commit 356bec0 into main Sep 11, 2026
1 check passed
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