Skip to content

Let one Access service token start and stop sessions - #31

Merged
JarenKempton merged 1 commit into
mainfrom
service-token-bar-access
Nov 8, 2026
Merged

JarenKempton merged 1 commit into
mainfrom
service-token-bar-access

Conversation

@JarenKempton

Copy link
Copy Markdown
Owner

Why

Service tokens can currently only open the read-only live event stream. A desktop client (an Omarchy status-bar widget) needs to show the current session and totals and to start or stop a session without a browser sign-in.

What changes

  • requireAccess now returns which service token made the request (its Client ID from the Access JWT's common_name), not just that one did.
  • New src/lib/service-access.ts decides what a service token may do:
    • Every service token: GET /api/v1/live, unchanged.
    • The token named by the BAR_SERVICE_TOKEN Worker secret: additionally GET status, companies, sessions, summary, companies/:id/period and /logos/*, and POST to start a session or stop one.
    • Anything else for that token: 403 service_token_forbidden. That covers editing or deleting sessions, companies, devices, logos, pay periods and exports.
  • Other service tokens still get 403 service_token_read_only everywhere except the live stream. Without the secret, behaviour is identical to today.
  • The Client ID is kept out of the repository and read from a Worker secret. docs/deployment.md documents the setup.

Testing

  • pnpm check, pnpm format:check and pnpm deploy:check pass.
  • pnpm test passes: 38 tests, 5 of them new in test/service-token.test.ts. The new tests cover the bar token's allowed reads and its start/stop round trip, a 403 on 11 off-limits routes, other tokens staying read-only, and no widening when the secret is unset.

Rollout

  1. Set the secret: pnpm exec wrangler secret put BAR_SERVICE_TOKEN, using the token's <id>.access Client ID.
  2. Merge. CI deploys.

🤖 Generated with Claude Code

Service tokens could only open the live event stream. A desktop client
such as a status-bar widget also needs to read the current status and
totals and to start or stop a session.

The token whose Client ID matches the BAR_SERVICE_TOKEN Worker secret
may now GET status, companies, sessions, summary, company periods and
logos, and POST to start or stop a session. Anything else returns 403
service_token_forbidden. Every other service token keeps the existing
read-only behaviour, and without the secret nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JarenKempton
JarenKempton merged commit 59689d3 into main Nov 8, 2026
2 checks 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