picoclaw/web/backend/api
sky5454 06023c79fa
feat(launcher): standard HTTP login/setup/logout flow for dashboard, frontend and backend impl. and fix windows pid lock for ws (#2339)
* feat(launcher): replace token-in-logs auth with standard HTTP login flow

## Problem

Previously users had to find the one-time token from console logs or
log files to access the dashboard - a non-standard, error-prone workflow
with no clear path for changing credentials.

## Solution: standard HTTP API login with bcrypt-backed password store

### Auth flow (new)
1. First run: browser opens, session guard detects uninitialized state,
   redirects to /launcher-setup
2. User sets a password (min 8 chars) via POST /api/auth/setup {password, confirm},
   bcrypt(cost=12) hash stored in ~/.picoclaw/launcher-auth.db (SQLite)
3. Subsequent logins: POST /api/auth/login {password}, HttpOnly cookie
   picoclaw_launcher_auth (HMAC-SHA256 signed, 7-day expiry)
4. 401 on any API call, frontend redirects to /launcher-login
5. Logout: POST /api/auth/logout, cookie cleared, redirect to login

### Backend changes
- web/backend/api/auth.go: renamed Token to Password; added handleSetup;
  launcherAuthStatusResponse now includes Initialized bool; PasswordStore
  interface wires bcrypt store into handlers
- web/backend/dashboardauth/: new package - Store with New(dir) / Open(path);
  SetPassword (bcrypt cost=12), VerifyPassword, IsInitialized
  - sql.go: all DB-layer constants (DBFilename, sqliteDriver, bcryptCost,
    four SQL query strings) - compile-time constants, zero runtime overhead
- web/backend/middleware/launcher_dashboard_auth.go: /launcher-setup and
  /api/auth/setup added to public paths
- web/backend/main.go:
  - dashboardauth.New(picoHome) replaces manual path construction
  - maskSecret(): suffix only revealed when >=5 chars hidden (length >= 12),
    preventing 8-char minimum passwords from leaking their tail
- web/backend/main_test.go: TestMaskSecret updated with boundary cases

### Forward-compatibility: pkg/credential integration

If the dashboard password is later reused as the enc:// passphrase,
the bcrypt hash in launcher-auth.db becomes an offline oracle.
Recommended mitigation (not yet implemented): derive two independent
subkeys via HKDF before use:

  bcrypt(HKDF(password, info="picoclaw-dashboard-login-v1"))  stored in DB
  HKDF(password, info="picoclaw-credential-enc-v1")           passed to PassphraseProvider

This isolates the two domains: cracking the bcrypt hash yields only the
login subkey, which is computationally independent of the enc:// subkey.

* fix(auth): replace wastedassign ok := false with var ok bool

* refactor(tray): remove copy-token clipboard feature

Dashboard login now uses standard web auth (bcrypt + session cookie).
The system tray 'Copy dashboard token' menu item is no longer needed.

- Delete tray_offers_copy.go and tray_offers_copy_stub.go
- Remove mCopyTok menu item and clipboard handler from systray.go
- Remove launcherDashboardTokenForClipboard var from main.go
- Remove MenuCopyToken/MenuCopyTokenHint keys from i18n.go

* feat(launcher-ui): standard HTTP login/setup/logout flow for dashboard

Replaces the previous "find token in logs" workflow with a proper
browser-based authentication UI backed by the new /api/auth/* endpoints.

### New pages
- /launcher-setup: first-run password initialization form (password +
  confirm, min 8 chars); calls POST /api/auth/setup; redirects to login
  on success
- /launcher-login: standard password login form; calls POST /api/auth/login;
  sets HttpOnly session cookie on success

### Session guard (src/routes/__root.tsx)
A useEffect on every non-auth page load calls GET /api/auth/status:
- initialized=false  -> redirect to /launcher-setup
- authenticated=false -> redirect to /launcher-login
This ensures the setup/login UI is shown even when the ?token= URL
mechanism auto-logs in (first-run case).

### Logout button (src/components/app-header.tsx)
IconLogout button added to the header with a confirm AlertDialog;
calls POST /api/auth/logout then redirects to /launcher-login.

### API layer
- src/api/launcher-auth.ts: LauncherAuthStatus gains initialized bool;
  postLauncherDashboardSetup() added; LauncherAuthTokenHelp removed
- src/api/http.ts: 401 guard uses isLauncherAuthPathname() (covers both
  /launcher-login and /launcher-setup) to prevent redirect loops
- src/lib/launcher-login-path.ts: isLauncherSetupPathname() and
  isLauncherAuthPathname() added

### Routing
- src/routeTree.gen.ts: /launcher-setup route registered throughout
- src/routes/launcher-login.tsx: tokenHelp UI removed; useEffect added
  to redirect to setup when initialized=false

### i18n
- en.json / zh.json: launcherSetup block added; launcherLogin keys
  updated to use passwordLabel/passwordPlaceholder

* fix(lint): ts lint fixed 1

* fix(auth): detail auth error handle

* fix(login):  frontend web auth error handle

* fix(frontend): auth error handler 5xx
2026-04-08 21:43:51 +08:00
..
auth.go feat(launcher): standard HTTP login/setup/logout flow for dashboard, frontend and backend impl. and fix windows pid lock for ws (#2339) 2026-04-08 21:43:51 +08:00
auth_login_limiter.go feat(web): protect launcher dashboard with token and SPA login (#1953) 2026-03-29 13:11:43 +08:00
auth_test.go feat(launcher): standard HTTP login/setup/logout flow for dashboard, frontend and backend impl. and fix windows pid lock for ws (#2339) 2026-04-08 21:43:51 +08:00
channels.go refactor(web): load channel configs without exposing secret values (#2277) 2026-04-02 19:09:33 +08:00
channels_test.go refactor(web): load channel configs without exposing secret values (#2277) 2026-04-02 19:09:33 +08:00
config.go feat(web): add service log level controls (#2227) 2026-03-31 20:32:42 +08:00
config_test.go feat(web): add service log level controls (#2227) 2026-03-31 20:32:42 +08:00
gateway.go fix(gateway): validate PID ownership and clean stale pid files (#2422) 2026-04-08 14:23:21 +08:00
gateway_host.go use explicit port headers before falling back to wsPort in picoWebUIAddr 2026-03-31 02:11:17 -05:00
gateway_host_test.go feat(web): protect launcher dashboard with token and SPA login (#1953) 2026-03-29 13:11:43 +08:00
gateway_test.go fix(gateway): validate PID ownership and clean stale pid files (#2422) 2026-04-08 14:23:21 +08:00
launcher_config.go feat(web): persist dashboard token in launcher config (#2304) 2026-04-03 14:54:27 +08:00
launcher_config_test.go feat(web): persist dashboard token in launcher config (#2304) 2026-04-03 14:54:27 +08:00
log.go refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
model_status.go fix(api): enhance model availability probing with backoff and caching mechanisms (#2231) 2026-04-01 14:15:28 +08:00
model_status_test.go fix(api): enhance model availability probing with backoff and caching mechanisms (#2231) 2026-04-01 14:15:28 +08:00
models.go feat(provider): support custom headers injection for HTTP providers (#2402) 2026-04-07 16:05:21 +08:00
models_test.go feat(provider): support custom headers injection for HTTP providers (#2402) 2026-04-07 16:05:21 +08:00
oauth.go refactor: seperate security.yml for store keys 2026-03-22 01:55:00 +08:00
oauth_test.go refactor config and security to simplified the structure (#2068) 2026-03-28 00:03:34 +08:00
pico.go fix(gateway): validate PID ownership and clean stale pid files (#2422) 2026-04-08 14:23:21 +08:00
pico_test.go fix(gateway): validate PID ownership and clean stale pid files (#2422) 2026-04-08 14:23:21 +08:00
router.go feat(updater): robust self-update selection & extraction (nightly default) (#2201) 2026-04-01 23:41:32 +08:00
session.go feat(web): support image messages in pico chat (#2299) 2026-04-03 14:15:20 +08:00
session_test.go feat(web): support image messages in pico chat (#2299) 2026-04-03 14:15:20 +08:00
skills.go feat(web): add skill marketplace hub and registry install flow (#2246) 2026-04-01 19:25:31 +08:00
skills_test.go feat(web): add skill marketplace hub and registry install flow (#2246) 2026-04-01 19:25:31 +08:00
startup.go feat(web): add service log level controls (#2227) 2026-03-31 20:32:42 +08:00
startup_test.go feat(web): add service log level controls (#2227) 2026-03-31 20:32:42 +08:00
tools.go feat(tools): add SpawnStatusTool for reporting subagent statuses (#1540) 2026-03-17 14:41:43 +08:00
tools_test.go refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
update.go feat(updater): robust self-update selection & extraction (nightly default) (#2201) 2026-04-01 23:41:32 +08:00
version.go feat(web): display backend version info in sidebar (#2087) 2026-03-30 16:44:50 +08:00
version_test.go feat(web): display backend version info in sidebar (#2087) 2026-03-30 16:44:50 +08:00
wecom.go feat(web): add WeCom QR binding flow to channel settings (#1994) 2026-03-25 16:15:04 +08:00
weixin.go feat(web): improve Weixin channel binding flow (#1968) 2026-03-24 20:33:32 +08:00
weixin_test.go refactor config and security to simplified the structure (#2068) 2026-03-28 00:03:34 +08:00