Skip to main content
Version: 2.0.0

Get user permissions

To get all user permissions irrespective of the tenant, you can use the permit.GetUserPermissions function. This function determines all user permissions for every registered resource across all tenants.

Simple Usage

The permit.GetUserPermissions function accepts a "User" as input and optionally a list of tenants to filter, and returns an object containing the details about the request for each assigned tenant, including the assigned tenant's attributes, and the allowed permissions:

const { Permit } = require("permitio");

const permit = new Permit({token: "<YOUR_API_KEY>", ...});
const userPermissions = await permit.getUserPermissions("john@doe.com");

EAP: Enabling ABAC in user permissions

The permit.GetUserPermissions function can also find all permitted objects based on attribute-based rules (ABAC condition sets), however this calculation is a bit more expensive to run performance wise. For that reason, you have to manually turn on this capabality when needed.

Not all SDKs are supporting this feature at this point in time, you can directly call the PDP API if your SDK is not supporting it yet.

Assuming localhost:7766 is the PDP address relative to the caller:

curl --location 'http://localhost:7766/user-permissions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <api key>' \
--data '{
"user": {
"key": "eddie"
},
"resource_types": [
"document",
"__tenant"
],
"context": {
"enable_abac_user_permissions": true
}
}'

Filtering out the results

You can filter the results by any one of the following:

  • tenants - returns only the permissions for instances or globally for the specified tenants
  • resource_types - returns only the permissions for instances of the specified resource types
    • To get only top level accesses, please use the __tenant resource type
  • resources - returns only the permissions for the specified resource instances, format should be resource_type:resource_key
const { Permit } = require("permitio");

const permit = new Permit({token: "<YOUR_API_KEY>", ...});
const userPermissions = await permit.getUserPermissions(
"john@doe.com",
["tenant-1", "tenant-2"], // tenants
["document:doc-1", "document:doc-2"] // resources
["document", "__tenant"], // resource_types
);