Skip to content

Check a permission from your API

Your API can ask the identity server whether the caller is allowed to do something, at the moment of the request. The answer reflects every grant as it stands at that moment, including grants on one resource and grants with conditions, which the token’s claims don’t carry. This page shows the request, the response, and the errors.

To decide from the token alone instead, see Read roles and permissions from the token.

  • Roles and bindings in the audience’s catalog. See Define roles and grant them. The examples on this page continue from that page.
  • Identity server 1.98.0 or later.
  • The Admin API host of the install that serves your issuer, reachable from your API’s backend. The examples call it API_HOST.
    • On the Authwise service, the host is api.authwise.com.
    • On your own install, it’s a host from the install’s networking.api.hosts. If you put only part of the Admin API on a public hostname, as in Expose part of the Admin API, the paths under /v1/access: stay private. Call the API from inside the cluster, or add that prefix to the public paths.

The request carries no subject. The identity server takes the subject from the access token that you send as the bearer:

  • The token’s sub is the subject: the person, or the application for a client_credentials token.
  • The token’s aud selects the catalog: the audience that the token was issued for.
  • The token’s iss must be an issuer of the install you call. The identity server verifies the signature against that issuer’s keys, and the token must not be expired.

Your API doesn’t need a credential of its own. It forwards the access token that it received from the caller, and the answer is about that caller. An API can’t ask about someone else with this endpoint.

Send the permission’s name. With no resource, the question is about the whole API:

Terminal window
curl -s https://API_HOST/v1/access:check \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"permission":"invoices.write"}' | jq
{
"decision": {
"allowed": true,
"reason": "binding at / grants invoices.write",
"bindingId": "axb-g54uczbi7tzx"
}
}

Replace ACCESS_TOKEN with the access token that the caller sent to your API.

When the caller isn’t allowed, the response has no allowed field:

Terminal window
curl -s https://API_HOST/v1/access:check \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"permission":"invoices.approve"}'
{"decision":{"reason":"no binding grants invoices.approve on /"}}
FieldValue
decision.allowedtrue when the caller is allowed. Absent when the caller isn’t.
decision.reasonA sentence for logs and for people. Don’t parse it.
decision.bindingIdThe binding that granted the permission. Absent on a denial.

Allow the request only when the response status is 200 and decision.allowed is true. Treat every other outcome, including an error or a timeout, as a denial.

To decide what to show on a page, or to check a batch, send up to 100 checks in one request. The decisions come back in the same order:

Terminal window
curl -s https://API_HOST/v1/access:bulkCheck \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"checks":[{"permission":"invoices.read"},{"permission":"invoices.write"},{"permission":"invoices.approve"}]}'
{"decisions":[{"allowed":true,"reason":"binding at / grants invoices.read","bindingId":"axb-g54uczbi7tzx"},{"allowed":true,"reason":"binding at / grants invoices.write","bindingId":"axb-g54uczbi7tzx"},{"reason":"no binding grants invoices.approve on /"}]}

Each entry of checks takes the same fields as a single check, so one request can mix permissions and resources.

To ask about one object in your API, add resource with the object’s type and ID. A grant on the resource counts, and so does a grant on anything above it, up to the whole API. To set up such grants, see Grant access to one resource.

Terminal window
curl -s https://API_HOST/v1/access:check \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"permission":"invoices.approve","resource":{"type":"invoice","id":"inv-9"}}'
{"decision":{"allowed":true,"reason":"binding at account/acc-3 grants invoices.approve","bindingId":"axb-g51g0h16x7x5"}}

The reason names the resource that the grant is on. Here the caller holds the role on the account that contains the invoice.

Set both type and id, or neither. The check doesn’t tell you whether the resource exists: the identity server compares the strings that you send with the grants that it holds. Confirm that the object exists in your own data.

A binding can carry a condition, an expression over attributes of the request. Your API supplies those attributes in attributes, a map of string keys to string values. Each key starts with request., subject., or resource.:

Terminal window
curl -s https://API_HOST/v1/access:check \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"permission":"invoices.export","attributes":{"request.network":"office"}}'
{"decision":{"allowed":true,"reason":"binding at / grants invoices.export","bindingId":"axb-g54uczbi7u2x"}}

With a value that the condition rejects, the reason says so:

{"decision":{"reason":"a binding grants invoices.export on / only under condition axc-g54uczbi7u07, which did not hold"}}

The identity server fills in no attribute. Whoever calls the check chooses them, so call it from your backend with values that your backend established, and never pass values through from the caller unchecked. To write a condition, see Add a condition to a grant.

To build a list, such as the accounts that the caller can approve invoices in, ask for every resource of one type where the caller holds a permission:

Terminal window
curl -s https://API_HOST/v1/access:lookupResources \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"permission":"invoices.approve","resource_type":"account"}'
{"resources":[{"type":"account","id":"acc-3"}]}

The type must be one that the audience declares. The answer covers the resources that the identity server knows of: those that a binding names and those that a parent link names. See Find the resources a caller can reach.

StatusBodyCause
401UnauthenticatedNo bearer, an expired or malformed token, a token whose issuer this install doesn’t serve, or a token whose aud isn’t an audience of its issuer.
400check: permission is requiredThe request has no permission.
400check: resource type and id must both be set, or both be empty for the platform rootresource has a type without an ID, or an ID without a type.
400bulk_check: 101 checks exceeds the maximum of 100Too many checks in one request.
500evaluate condition: … no such keyA condition reads an attribute that the request didn’t send. Send the attribute, or write the condition to test for it first.
501resource type … cannot be enumeratedlookupResources was asked for a type that the audience doesn’t declare.

A denial is not an error. It’s a 200 whose decision has no allowed field.