Scopes
A person can let another application act for them, such as a partner's app
holding a token their company's identity provider issued it. Such a token
carries scopes: what the person let that application do.
external_token: declares the scopes its
tokens carry, and every such token is narrowed to them. Your own app can
issue its API tokens narrowed the same way, from the scopes
api_token: declares. A narrowed token may
do what both the person's grants and its scopes allow, and never more
than the person could do themselves.
An entity's policy: says, in scopes:, which scope a narrowed token
needs for each effect, as well as a grant. Here a partner's app reads a
diarist's notes with notes:read, and writes them with notes.write:
config { audience: Text issuer: Url}principal { user: { subject: Diarist.handle }}authentication { browser_session: { cookie: "notebook_session" } external_token: { issuer: config.issuer audience: config.audience scopes: { notes_read: "notes:read" notes_write: "notes.write" } }}type Handle = Text { max_length: 40}entity Diarist { id: Uuid handle: Handle { unique: true } policy: { read: [id] }}entity Note { id: Uuid diarist_id: Diarist.id { on_delete: OnDelete.cascade } text: Text policy: { create: [diarist_id] read: [diarist_id] update: [diarist_id] delete: [diarist_id] scopes: { create: OAuthScope.notes_write read: OAuthScope.notes_read update: OAuthScope.notes_write } }}
- Each effect names one scope,
OAuthScope.<name>.OAuthScopehere holds only the scopesauthentication.jadpodeclares, so a misspelt or undeclared scope ispolicy.binding_invalid. A list would read as "any of", and a scope must hold as well as a grant, so there is none. - An effect
scopes:leaves out is refused to every narrowed token. So no token deletes a note, and none reads aDiarist, whose policy names no scope: a new entity is never open to other applications by accident. Access.publicandAccess.authenticatedare grants like any other: a narrowed token still needs the effect's scope.- Browser sessions and service keys carry no scopes, and neither do
schedules and subscribers, so scopes never touch them. Nor do they touch
a token from a provider whose
external_token:declares none, or an API token issued withoutscopes:. An API token issued with them is narrowed exactly as a provider's token is.
A narrowed token is refused as any caller policy refuses is (When policy
says no): a note it may not read is the code's own
not_found failure, a list leaves it out, and a create is 403
not_permitted. The check is in each statement's WHERE, as every grant
is.
Some things no effect's scope covers, so a narrowed token is refused them:
- an action listed under
actions:that is checked as it starts, since no entity'sscopes:names it. A listed query is let through, and its records are still filtered by their entity'sread:scope; - starting a session or issuing an API token,
sessions.startandsessions.issue_token(403not_permitted), since either would carry the person's whole authority; - looking a person up by email,
<Entity>.lookup(Looking up one person by email), since no scope names a lookup; - a slot for an upload, unless it carries the scope of its entity's
create:orupdate:.
The permissions report gives each entity a
"scope" row, with "refused" where no scope lets a narrowed token in, and
access.jadpo_record keeps the declared scopes and each effect's.
Loosening them needs a person (Protecting policy). A
route test says which scopes its token carries with scopes:
(Signing in for a route test).
Markdown for agents: /docs/scopes.md.Built from Jadpo's main branch at commit 9080dc3.