Authentication

Authentication #

Microbooks is a full OAuth 2.0 authorization server, following OAuth 2.1 practice for third-party apps: authorization code with PKCE, rotating refresh tokens, no implicit flow. Every request to the API is authenticated with a bearer token — a signed JWT issued by the auth service and verified by the resource APIs against the platform’s published keys (JWKS).

The password grant is also enabled, but only as the mechanism behind the first-party login endpoint. It is not the path to use for an integration: use a personal access token or the OAuth flow instead.

There are three ways to get a token. Pick the one that matches what you are building:

You are building…UseWhere to start
A script, CI job, or the MCP serverPersonal access tokenPersonal access tokens
An app that accesses other users’ booksAuthorization code + PKCEOAuth flow
A quick experiment against your own accountPassword loginLogin

Scopes #

Tokens carry scopes, and the resource APIs enforce them: GET requests need the :read scope, writes need :write, and closing or reopening months, or changing a Reporting Period’s status, needs books:close.

ScopeGrants
books:readRead accounting records
books:writeCreate and update accounting records
books:closeClose and reopen months (Month Close) and change Reporting Period statuses
payments:readRead payment records
payments:writeCreate and update payment records

An account can only grant the scopes it is entitled to — a standard account gets the books:* scopes.

books:close #

books:close is kept apart from books:write so that a token can draft and post entries without being able to close or reopen a period. It is never part of an ordinary login or registration: you get it only by naming it on a personal access token or by approving an app that asks for it on the consent screen. Holding the scope is not enough on its own — the books API also requires the caller to be the owner of the entity being closed.

It is what POST /books/v1/month-close/close, POST /books/v1/month-close/reopen and a change of a Reporting Period’s status (PUT /books/v1/reporting-period/{id}, or POST /books/v1/reporting-period with a status other than OPEN) require, in place of books:write: a token with books:write alone is refused with 403 insufficient_scope, and one with books:close alone can close and reopen months but not post. Reading the months, their history and the verification (GET /books/v1/month-close, /events, /verify) needs books:read as usual. See Month Close.

Do not give books:close to automated agents. Leave it off tokens used by the MCP server, CI jobs and other unattended integrations; close periods yourself, with a token you create for that purpose.

Token lifetimes #

TokenLifetimeNotes
Access token15 minutesSent as Authorization: Bearer <token>
Refresh token30 daysRotates on every use — the old one is revoked when redeemed
Personal access token1 yearLong-lived by design; revoke any you stop using

Because access tokens are short-lived, any long-running integration must either use a personal access token or implement refresh.