Repository navigation
Let one Access service token start and stop sessions - #31
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
requireAccessnow returns which service token made the request (its Client ID from the Access JWT'scommon_name), not just that one did.src/lib/service-access.tsdecides what a service token may do:GET /api/v1/live, unchanged.BAR_SERVICE_TOKENWorker secret: additionallyGETstatus, companies, sessions, summary,companies/:id/periodand/logos/*, andPOSTto start a session or stop one.service_token_forbidden. That covers editing or deleting sessions, companies, devices, logos, pay periods and exports.service_token_read_onlyeverywhere except the live stream. Without the secret, behaviour is identical to today.docs/deployment.mddocuments the setup.Testing
pnpm check,pnpm format:checkandpnpm deploy:checkpass.pnpm testpasses: 38 tests, 5 of them new intest/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
pnpm exec wrangler secret put BAR_SERVICE_TOKEN, using the token's<id>.accessClient ID.🤖 Generated with Claude Code