scute.authz runs checks against the app's policy with the secret key. A check returns a Scute::Authz::Decision.
scute = Scute::Client.newdecision = scute.authz.check(user_id: user.scute_id, action: "refund", resource: "invoice:42")decision.allowed? # true only for a plain allowdecision.explanation # "Ada can refund invoice 42: ..."Check#
check(user_id:, action:, resource: nil, context: nil, challenge: nil, approval: nil) calls POST /v1/auth/:app_id/authz/check.
The decision#
| decision.decision | Predicate | Meaning |
|---|---|---|
| "allow" | allowed? | Go ahead. |
| "allow_with_step_up" | step_up? | Allowed after the user verifies. decision.step_up has method and authorizes_action. |
| "allow_with_approval" | needs_approval? | Allowed after a reviewer approves. |
| "deny" | denied? | Not allowed. |
allowed? is false for a step-up or approval answer.
| Field | Content |
|---|---|
| reason | Why, for example role_grant, verified, approved, condition_failed, no_role_grants_permission, unknown_permission |
| permission | The permission checked, for example "invoice:refund" |
| roles | Roles that grant it (an Array, [] when none) |
| path, conditions | As the API returns them for the check |
| step_up | Step-up details for allow_with_step_up |
| approval | Approval details for allow_with_approval |
| agent | Present on agent checks |
| explanation | A sentence that explains the answer |
| say | A line for the person, on agent checks that are not a plain allow |
Batch checks#
check_batch(checks) sends up to 100 checks, for any users, in one call (POST /v1/auth/:app_id/authz/check-batch) and returns an Array of decisions in the same order. More than 100 raises ArgumentError before any call.
decisions = scute.authz.check_batch([ { user_id: "u1", action: "read", resource: "invoice:1" }, { user_id: "u2", action: "refund", resource: "invoice:1" }])decisions.map(&:decision) # ["allow", "allow_with_step_up"]Each entry takes the same keys as check.
Permissions#
permissions(user_id, resource: nil) returns the roles and permissions a user holds, app-wide or on one object.
scute.authz.permissions(user_id)# { "roles" => ["billing"], "permissions" => ["invoice:read", "invoice:refund", ...],# "step_up" => ["invoice:refund"], "approval" => ["invoice:void"] }scute.authz.permissions(user_id, resource: "document:42")Authorized users#
authorized_users(action:, resource: nil, limit: nil, offset: nil) returns who may do something, paged.
who = scute.authz.authorized_users(action: "void", resource: "invoice", limit: 50)who["permission"] # "invoice:void"who["everyone"] # falsewho["users"].map { |u| u["id"] }Data filters#
filter(user_id:, action:, resource_type:, context: nil) returns a filter for list queries in filter:
- "all": the user may see every record of the type.
- "none": the user may see none.
- A Hash: a condition tree over your own fields, with the user filled in (for example on resource.owner).
result = scute.authz.filter(user_id: user_id, action: "read", resource_type: "document")case result["filter"]when "all" then Document.allwhen "none" then Document.noneelse # translate the condition tree into your queryendThe Ruby SDK does not compile the condition tree into SQL.
Policy snapshot#
snapshot returns the policy as a signed snapshot (an RS256 JWS) from GET /v1/apps/:app_id/authz/snapshot.
snapshot = scute.authz.snapshotsnapshot["token"] # the JWS; claims include "typ" => "scute-authz-snapshot", "version", "policy"snapshot["jwks"] # where the verification keys aresnapshot["version"]The Ruby SDK fetches the snapshot but has no local decision engine: it does not verify or evaluate it. Use check for decisions.
In a controller#
scute_authorize! and scute_can? run check as the signed-in user. See Rails integration.