Skip to content

Define and check permissions in code

Your application decides what its users may do. FlowCatalyst holds who has which role; your code holds what each role allows and checks it. Both halves live in your code: you declare the permissions and roles, sync them so the platform (and administrators) know them, and check permissions at runtime. Permissions and roles explains the rules behind this page.

  • A permission has four segments: application:context:aggregate:action, for example orders:sales:order:cancel. The first segment is your application’s code; the platform refuses a role that holds another application’s permission (PERMISSION_OUTSIDE_APPLICATION).
  • A role is application:name, for example orders:dispatcher. You declare the short name; sync adds the prefix and lower-cases it.
  • A held permission may use * for whole segments (orders:sales:*:*). Checks match segment by segment, so orders:sales:order:* satisfies orders:sales:order:cancel.
set := sync.ForApplication("orders").
AddRole(sync.MakeRole("dispatcher").
WithDisplayName("Dispatcher").
WithDescription("Plans and cancels deliveries").
WithPermissions("orders:sales:order:view", "orders:sales:order:cancel").
ClientManagedEnabled()). // client administrators may assign it
AddRole(sync.MakeRole("viewer").WithPermissions("orders:sales:order:view"))

Client-managed roles. A role marked client-managed may be assigned by a client’s own administrators to users of their client (a client may only be given roles of applications it is entitled to). Leave it off for roles only your own staff should hand out.

Sync the set with the rest of your definitions on each deploy (php artisan flowcatalyst:scan && php artisan flowcatalyst:sync in Laravel, which also seeds Spatie’s tables when spatie/laravel-permission is installed). Permissions have no endpoint of their own: they reach the platform on the roles that grant them, and the console shows them under each role.

Role sync is all or nothing (one bad role refuses the payload). With remove-unlisted, a role you deleted from code is removed, unless it is still assigned to someone: then the sync is refused (ROLE_HAS_ASSIGNMENTS) rather than silently taking access away.

People get roles from administrators (the console’s Users page), from your application’s own user management (create users and invitations), from principal sync, or from their organisation’s identity provider at sign-in. Assigning a name that is not a role is refused.

Where the permissions come from depends on how the caller arrived:

Caller Carries Permissions
A person signed in to your app The id_token’s roles (your application’s only) Mapped by your code from roles
A service calling your API with a platform access token scope (the granted permissions), roles Read from scope
// the same map as the roles you sync
const rbac = defineRbac()
.role("orders:dispatcher").grants("orders:sales:order:view", "orders:sales:order:cancel")
.role("orders:viewer").grants("orders:sales:order:view")
.build();
// pass { rbac } to flowcatalystAuth, then in a route:
if (!req.principal!.hasPermissionTo(["orders:sales:order:cancel"])) {
throw app.httpErrors.forbidden();
}
req.principal!.hasAnyPermissionTo(["orders:sales:order:cancel", "orders:sales:order:view"]);
req.principal!.hasRole("orders:dispatcher");

Wildcards are suffixes at segment boundaries: orders:* matches orders:sales:order:view.

Keep the runtime map and the synced roles in one place where you can (for example, generate the defineRbac() catalogue from the same constants as the synced roles), so a role never means one thing on the platform and another in your checks.