scute.authz asks Scute's engine, with the secret key, what a user may do. Roles, permissions and conditions come from the app's policy, which you manage in the dashboard or the API.
decision = scute.authz.check( user_id=session.user_id, action="refund", resource="invoice:42", context=session.authz_context(),)if decision.allowed: ...Check one action#
scute.authz.check(*, user_id, action, resource=None, context=None, challenge=None, approval=None) -> DecisionArguments left as None (and an empty context) are not sent. The call is POST /v1/auth/:app_id/authz/check.
Support sessions
Pass session.authz_context() in context on every check made for a request. When someone is signed in as the user, it adds {"impersonated": True, "actor": ...} and the engine refuses permissions marked "not while impersonating". The FastAPI and Flask helpers do this for you.
Decision#
Decision is a frozen dataclass built from the API's answer.
| Field | Type | Meaning |
|---|---|---|
| decision | str | allow, deny, allow_with_step_up or allow_with_approval |
| reason | str or None | Why, for example role_grant or no_role_grants_permission |
| permission | str or None | The permission slug checked, for example invoice:refund |
| roles | list[str] | Roles that granted it |
| explanation | str or None | A readable sentence |
| step_up | dict or None | Step-up details on allow_with_step_up |
| approval | dict or None | Approval details on allow_with_approval |
| say | str or None | A line for the person, on an agent's checks |
| raw | dict | The full API answer |
| Property | True when |
|---|---|
| allowed | decision == "allow" only |
| needs_step_up | decision == "allow_with_step_up" |
| needs_approval | decision == "allow_with_approval" |
allowed is False for a step-up or approval answer. Treat those as "not yet": the user verifies, or a reviewer approves, and you check again.
if decision.allowed: do_refund()elif decision.needs_step_up: ... # ask the user to verify, then check againelif decision.needs_approval: ... # a reviewer approves, then check againelse: raise PermissionError(decision.explanation)Check many at once#
scute.authz.check_batch(checks: list[dict]) -> list[Decision]Each dict has the same keys as check (user_id, action, resource, context, ...). None values are dropped. At most 100 checks per call (Authz.BATCH_LIMIT); more raises ValueError before any request. It returns one Decision per entry in the API's results.
decisions = scute.authz.check_batch([ {"user_id": user_id, "action": "read", "resource": "invoice:42"}, {"user_id": user_id, "action": "refund", "resource": "invoice:42"},])A user's permissions#
scute.authz.permissions(user_id: str, resource: str | None = None)GET /v1/auth/:app_id/authz/users/:user_id/permissions, optionally for one resource. Returns the API's JSON.
Who may do an action#
scute.authz.authorized_users(*, action: str, resource: str | None = None, limit: int | None = None, offset: int | None = None)GET /v1/auth/:app_id/authz/authorized-users. Returns the API's JSON.
Not in this SDK#
- Filters (which rows of a type a user may act on): call POST /v1/auth/:app_id/authz/filter with scute.request. See the API reference.
- Policy import, role assignment and access requests: use the API.
- Offline decisions: see Local decisions.