Ruby SDK

Authorization

Ask Scute's engine whether a user may do something, in one call or a batch, list a user's permissions, and build data filters for list queries.

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.

user_idStringrequired
The Scute app user id.
actionStringrequired
The action, for example "refund".
resourceString or Hash
"invoice:42", or { type: "document", key: "D-1", attributes: { owner: user_id } }.
contextHash
Request context for conditions. Pass session.authz_context for an impersonated session.
challengeString
A completed step-up's token, for an allow_with_step_up answer. See Step-up.
approvalString
An approved access request's id, for an allow_with_approval answer. Spent by the allow it produces. See Access requests.

The decision#

decision.decisionPredicateMeaning
"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.

FieldContent
reasonWhy, for example role_grant, verified, approved, condition_failed, no_role_grants_permission, unknown_permission
permissionThe permission checked, for example "invoice:refund"
rolesRoles that grant it (an Array, [] when none)
path, conditionsAs the API returns them for the check
step_upStep-up details for allow_with_step_up
approvalApproval details for allow_with_approval
agentPresent on agent checks
explanationA sentence that explains the answer
sayA 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 queryend

The 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.