feat(auth): bootstrap API token from URL/session#806
feat(auth): bootstrap API token from URL/session#806ErikBjare merged 2 commits intoActivityWatch:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #806 +/- ##
==========================================
+ Coverage 29.96% 31.53% +1.57%
==========================================
Files 32 32
Lines 1829 1877 +48
Branches 317 331 +14
==========================================
+ Hits 548 592 +44
- Misses 1260 1264 +4
Partials 21 21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Greptile SummaryThis PR implements API auth bootstrapping in aw-webui: a credential read from a URL query parameter is persisted to tab-scoped Confidence Score: 5/5Safe to merge — implementation is correct, prior P0/P1 concerns are resolved, and tests cover all key paths. All three previously raised issues (loose No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant awclient.ts
participant sessionStorage
participant history
participant AxiosDefaults
Browser->>awclient.ts: createClient()
awclient.ts->>awclient.ts: loadApiTokenFromBrowser()
awclient.ts->>Browser: getApiTokenFromLocation(window.location)
alt token in URL
awclient.ts->>sessionStorage: setItem('aw-api-token', token)
awclient.ts->>history: replaceState() — strip ?token= from URL
awclient.ts-->>awclient.ts: return urlToken
else no URL token
awclient.ts->>sessionStorage: getItem('aw-api-token')
awclient.ts-->>awclient.ts: return storedToken (or null)
end
awclient.ts->>AxiosDefaults: applyApiToken — set headers.common.Authorization
Reviews (2): Last reviewed commit: "fix(auth): address review feedback — typ..." | Re-trigger Greptile |
…isolation
- Replace `defaults: any` with `{ req: AxiosInstance }` for proper type checking
- Document token URL exposure window with mitigation guidance
- Use jest.resetModules() to reset module-level _client between tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed the Greptile findings in c00a46f:
|
|
@greptileai review |
Summary
?token=...from the browser URL into tab-scopedsessionStorageAuthorization: Bearer ...to the shared aw-webui client defaultsContext
This is the remaining aw-webui piece of the ActivityWatch API auth rollout discussed in ActivityWatch/activitywatch#1199. It makes browser access work when a launcher/WebView opens aw-webui with a tokenized URL.
Testing
npx eslint --ext=js,ts src/util/awclient.ts test/unit/awclient.test.jsnpx jest --runInBand --runTestsByPath test/unit/awclient.test.js test/unit/NewReleaseNotification.test.js test/unit/store/activity.test.node.tsnpx tsc --noEmit --pretty false