Skip to content

TypeScript API / contentia/server/api / createScopePolicy

Function: createScopePolicy() ​

ts
function createScopePolicy(options?): (ctx) => boolean;

Build an authorize-compatible policy that grants a request iff the principal's scopes satisfy the required scope for that request. Drop it in as authorize, or wrap it for finer control.

Parameters ​

ParameterType
options?ScopePolicyOptions

Returns ​

(ctx) => boolean

Example ​

Plain CMS, scopes carried on the session's user:

ts
contentiaApi({ ..., authorize: createScopePolicy() });

Fails closed: a principal with no scopes is denied everything except requests the mapping returns null for (e.g. session). Populate user.scopes in your authenticateAccessToken callback, typically via resolveBearer from the OAuth session's granted scope.