api-tokens/v1

An app's API tokens, as other extensions use them. Tokens are scoped: a token limited to scopes works only on the requests those scopes reach. Extensions register their own scopes, read the token a request came with, and limit requests they make on someone's behalf, all through this package.

A service with its own API (tokens.go), served at /api/_c/api-tokens/v1.

Use

HTTP What it does
GET /api/_c/api-tokens/v1/scopes the scopes a token may hold, and who may own tokens
GET /api/_c/api-tokens/v1 your tokens (superusers: ?owner=, ?ownerCollection=)
POST /api/_c/api-tokens/v1 create one ({name, scopes, expires|ttl}); the secret is shown once
DELETE /api/_c/api-tokens/v1/{id} revoke one
POST /api/_c/api-tokens/v1/revoke-all revoke all of yours

In Go:

if tk, ok := tokensv1.Contract.Of(app); ok {
	tk.RegisterScope(tokensv1.Scope{Name: "notes:write", Description: "Change notes",
		Paths: []string{"/api/collections/notes/records"}, Methods: []string{"POST", "PATCH", "DELETE"}})
}
g := tokensv1.FromRequest(e)                       // the request's token, or nil (a JWT, or none)
ctx = tokensv1.WithScopes(ctx, []string{"notes:read"}) // requests made with ctx count as limited to these scopes

A scope registered with Values can be held for some values only: name=value in the token's scopes (instances=abc123), the bare name meaning every value. Paths don't see values, so the route checks them:

g := tokensv1.FromRequest(e)
if g != nil && !g.HasScopeFor("instances", id) { return e.ForbiddenError("Not this instance.", nil) }
vals, all := g.ScopeValues("instances")           // all: every value

HoldsScope, CoversScope, ValuesOf and IntersectScopes do the same on a plain scope list.

Provide

Implement tokensv1.Issuer (Verify, RegisterScope, Scopes, Reaches), authenticate requests that carry a token (setting tokensv1.RequestKey to the *Grant), honour WithScopes limits, and serve the token API (the provider binds its own routes, extkit.RouteBinder).

Commands and APIs

Its own HTTP API under /api/_c/api-tokens/v1/, described above. It has no generated commands or MCP tools. Remote CLI explains how PocketOne apps are managed from afar.

Extensions

Extension
api-tokens provides
deploy works with
mcp works with
remotes works with

License

MIT