Narrowing an API token to scopes
A token for an app that should do less than its person may, such as a
read-only widget, is issued narrowed to some scopes. api_token:
declares them as external_token: does, each a name and its
scope-token, and sessions.issue_token names them:
authentication { api_token: { scopes: { notes_read: "notes:read" notes_write: "notes:write" } }}action widget_sign_in(token: InvitationToken) fails InvitationExpired -> AppSignedIn { var invitation: Invitation = attempt Invitation.redeem(token) return AppSignedIn { token: sessions.issue_token(invitation.member_id, scopes: [OAuthScope.notes_read]) }}
- Policy holds a narrowed token exactly as it holds a provider's (Scopes): it does what both its person's grants and its scopes allow.
scopes:comes after the user'sidand lists each scope once, at least one; each is oneapi_token:declares (type.token_scopes_invalid). A token issued withoutscopes:may do whatever its person may, as every token issued before scopes did.- A scope both
api_token:andexternal_token:declare is one scope: its name reads the same scope-token in both, or it issemantic.auth_setting_invalid. jadpo_sessionskeeps the scope-tokens beside the token's verifier, and with a revocation delay the token's signed part carries them, so a delay never widens a token.IssuedToken'sscopeslists them, and isnonefor a token that isn't narrowed and for a browser session.
Markdown for agents: /docs/narrowing-an-api-token-to-scopes.md.Built from Jadpo's main branch at commit 9080dc3.