E3 of the extensibility plan. An OAuth app is a third-party (or in-house) program that calls API v1 on behalf of a user, or on its own, within scopes an administrator allowed and a user (or the administrator) granted.
Register an app
Setup › Integrations › Apps and Access (integrations.apps). An app has a name, logo, publisher, redirect URIs and a
type:
- Confidential (a server): a client secret (
dcs_…), shown once, rotatable (the old one stops at once). - Public (a mobile or single-page app): no secret; PKCE (S256) is mandatory. Redirect URIs may use the app's own
link scheme (
com.example.app:/callback,cursor://…), never an unsafe one (javascript:,data:,file:…).
Redirect URIs are https (http only on localhost) and matched exactly. A confidential app may also act on its own (client credentials): it gets a service user with the role and companies the administrator chooses - never a role the administrator does not hold.
Scopes
GET /api/admin/oauth/scopes lists the catalog, derived from the installed models:
| Scope | Means | Capabilities |
|---|---|---|
<family>.read |
read records of that model family (crm.read covers crm.*) |
records.read, data.raw |
<family>.write |
create, change, transition and delete them | + records.write |
events.subscribe |
own webhook subscriptions | integrations.webhooks |
documents.issue |
issue documents from templates | records.issue |
assistant.ask |
an AI app asks about records over MCP (mcp.md); reads nothing without a family read scope | assistant.ask |
assistant.propose |
an AI app suggests record changes the person applies in DrootERP (mcp.md) | assistant.ask |
offline_access |
a refresh token | - |
A token can do what both its scopes and its user (or service role) allow, company by company, re-read on every
request (a filter's $me is the person who granted it; a client-credentials token has no person behind it): demoting the user or revoking the grant takes effect at once. Capabilities no key may hold
(KEY_FORBIDDEN_CAPABILITIES) are never granted. App tokens work on /api/v1/* and /mcp only; a token bound to
MCP, and every token of an AI app that registered itself (POST /api/oauth/register, mcp.md) or that signs in
with a client ID metadata document (an https client_id), on /mcp only.
Fields only an integration writes
A field option, next to readOnly, readOnlyWhen and formOnly, marks a field the integration owns (a synced status,
an external id, a figure another system computes):
{ "fieldKey": "syncedStatus", "label": "Synced Status", "type": "text", "writtenBy": "integration" }
- People see it read-only in forms ("Set by an integration"); their writes are refused with 400 (
rule: "writtenBy"): forms, the record API or/api/v1with a person's session, imports and bulk actions. A form echoing the stored value still saves. - An integration writes it through
/api/v1: an API key or an OAuth app token (a client-credentials app acts as its service user). The system (scripts, flows, seeds, migrations) writes it too. writtenBytakes"integration"only; it can't go on a form-only, computed, rollup or mirror field.
Flows
Authorization code + PKCE:
- Send the user to
<app>/oauth/authorize?response_type=code&client_id=…&redirect_uri=…&scope=crm.read%20offline_access&state=…&code_challenge=…&code_challenge_method=S256. Withoutscope, the app asks for every scope its registration lists. Aresourcenaming the server's/mcpaddress binds the tokens to MCP (mcp.md); any otherresourceis refused. - The user sees the app, the scopes in plain language and chooses companies (Allow / Deny).
- The browser returns to
redirect_uri?code=…&state=…(orerror=access_denied). POST /api/oauth/token(form; HTTP Basic for a confidential client,client_idfor a public one) withgrant_type=authorization_code&code=…&redirect_uri=…&code_verifier=…. A code works once, for 10 minutes; a second use revokes the tokens the first bought.
Refresh: grant_type=refresh_token&refresh_token=… returns a new pair; the old refresh token is spent. Presenting a
spent one revokes the whole sign-in (theft detection). Client credentials: grant_type=client_credentials[&scope=…].
POST /api/oauth/revoke (RFC 7009; a refresh token takes its access tokens with it) and POST /api/oauth/introspect
(RFC 7662; a client sees only its own tokens). Lifetimes: OAUTH_ACCESS_TOKEN_TTL_SECONDS (default 1 hour),
OAUTH_REFRESH_TOKEN_TTL_DAYS (default 30).
Users see and revoke their grants in Me › Connected Apps; administrators on the app's page. Every grant, revoke, token
issue, token revoke and detected reuse is in the audit log (oauth.*).
Webhooks owned by an app
With events.subscribe an app manages its own subscriptions at /api/v1/webhooks (list, create, get, update, delete,
rotate secret). They receive only companies of the grant and only events about model families the app may read
(journal.posted needs accounting.read, stock.moved inventory.read). Revoking the grant, or disabling or
deleting the app, pauses them; they resume only once the app is connected again. See webhooks.md.
OpenAPI
GET /api/v1/openapi.json (any authenticated caller) is this tenant's OpenAPI 3.1 document: a path set per installed
model with its fields (custom ones included; enums from options; money as a decimal string in major units, marked
x-droot-money with its currency field and pinned decimals), the error envelope, pagination, Idempotency-Key and rate-limit headers, the security schemes (API key,
bearer, OAuth 2 with the scope catalog) and every event as an OpenAPI webhook. Metadata is tenant-wide, so one
document serves all companies; it is cached per metadata generation. Its info.version is the API version's major
and minor (API_VERSION, 2.0) with the metadata generation as the patch: 2.0.<generation>.
TypeScript client
npm run sdk -w kernel writes sdk/typescript (Apache-2.0, not published): the generic client. For typed methods per
model, generate from a tenant's document: npm run sdk -w kernel -- --spec openapi.json --out <dir>. The README there
shows authentication (API key, OAuth code + PKCE, client credentials) and webhook verification.