Skip to main content
Version: 1.0.0

SyncResources

To enforce permissions, you must first create resources and define actions that can be performed on those resources.

Then, you can create roles and assign them permissions for every resource/action combination. These roles can then be assigned to users.

For example: You can have the resource document and the action create for it. We can give permission to an editor role to create a document, and we can assign the editor role to a user named Bob.

This function helps you sync your resources and actions with Permit:

string resourceName = "document";
string actionName = "create";
// define the action title and description (can be empty)
ActionProperties actionProperties = new ActionProperties(
"Create document",
"Ability to create document"
);
// define the action
Dictionary<string, ActionProperties> resourceActions = new Dictionary<string, ActionProperties>{{ actionName, actionProperties }};
// define the resource with its actions
ResourceType[] resourcesToSync = { new ResourceType(resourceName, resourceActions) };
// sync the resources to Permit
var syncedResources = await permit.Api.SyncResources(resourcesToSync);

// SyncResources returns true if the resource was synced otherwise false