JavaScript SDK

Authorization on the server

Check permissions with the secret key, handle step-up and approval answers, list who may act, and read the decision log.

The check that guards a real action runs on your server with ScuteAdminApi. Scute decides and logs the decision; your server enforces it. Only decision.allowed lets an action through: it is true for a plain "allow" and never for "allow_with_step_up" or "allow_with_approval".

Check one permission#

const { data: decision, error } = await admin.authzCheck({  userId,  action: "edit",  resource: "project",});if (error || !decision?.allowed) return deny(decision?.explanation);
userIdstring | numberrequired
The app user.
actionstringrequired
The action, such as "edit". With a resource type it forms the permission project:edit.
resourcestring | { type, key?, attributes? }
"project", "project:42", or an object with attributes for conditions.
contextRecord<string, unknown>
Request attributes for conditions, such as { impersonated: true }.
challengestring
A completed step-up challenge's token, to satisfy allow_with_step_up.
approvalstring | number
An approved request's ID, to satisfy allow_with_approval. Spent when the answer is allow.

The answer is an AuthzDecision; its fields are on Permission checks in the browser. If Scute cannot be reached, treat the result as a deny.

authzCheckBatch(checks) takes up to 100 checks, for any users, and returns the decisions in order.

Step-up#

A permission marked "requires verification" answers allow_with_step_up until the user completes a fresh verification bound to it.

// 1. The check asks for a step-up: start it.const { data } = await admin.authzStartStepUp({ userId, decision });const token = data.challenge.token; // a code was sent; give the token to the page// 2. The user types the code: check it.const { error } = await admin.authzVerifyStepUp(token, code);if (error) return deny("That code didn't work."); // 422 with remaining_attempts in error.json// 3. Check again with the challenge.const { data: again } = await admin.authzCheck({ userId, action: "edit", resource: "project", challenge: token });

authzStartStepUp({ userId, decision?, permission?, method? }) creates a challenge with purpose step_up bound to decision.step_up.authorizes_action. method defaults to the one the decision asks for; pass one ("email_otp", "sms_otp", "entra_push", ...) when the decision allows any. It throws when it has no permission or no method.

The verification stays valid for the permission's verification_ttl.

Approval#

A permission marked "requires approval" answers allow_with_approval. The user files a request (scute.authz.requestAccess in the browser, or admin.authzCreateRequest from your server); a reviewer approves it; your backend checks again with approval: requestId. Each approval works once.

MethodDoes
authzRequests({ status?, userId? })Lists requests.
authzCreateRequest(userId, input)Files a request for a user: { role, resource?, duration?, reason? } or { action, resource?, reason? }.
authzDecideRequest(id, "approve" | "deny", { reviewerId?, note? })Decides. With reviewerId the decision is that user's (a reviewer, never the requester); without it, your backend's.

Who may do what#

const { data: perms } = await admin.authzUserPermissions(userId, { resource: "document:42" });// { user_id, roles, permissions, step_up, conditional?, verified_until?, resource?, resource_roles? }const { data: who } = await admin.authzAuthorizedUsers({ action: "approve", resource: "invoice", limit: 50 });// { permission, everyone, total, users: [{ id, email?, phone? }], resource?, conditions? }

everyone is true when a default role grants the permission.

Decision log#

const { data } = await admin.authzDecisions({ userId, decision: "deny", limit: 20 });// data.decisions: [{ id, at, permission, resource, decision, reason, roles, explanation, seq, row_hash, ... }]// data.next: pass as `before` for the older page

Filters: userId, agentId, taskId, decision, permission, resource, reason, since, until (ISO strings or Date), limit (1 to 200, default 50), before. Entries are written a moment after the check. Denials are always kept; plain allows are sampled at the log_allow_rate setting.

verifyDecisionLog({ from?, to? }) checks the log's hash chain and returns { ok, chain?, checked, head?, first_break? }. Keep head somewhere else to compare later.

Data filters#

For list endpoints, authzFilter returns a condition you turn into a query. See Data filters.