Skip to main content

Unassign a role from a user with the .NET SDK

permitClient.Api.UnassignRole() removes a role that a user holds within one tenant. Role assignments of the same role in other tenants stay in place. This reference is for .NET developers who revoke permissions from backend code.

UnassignRole signature

public async Task UnassignRole(string userKey, string roleKey, string tenantKey, string resourceInstanceId = null, string resource_type = null)

UnassignRole parameters

ParameterTypeRequiredDescription
userKeystringYesThe key of the user who holds the role.
roleKeystringYesThe key of the role to remove.
tenantKeystringYesThe key of the tenant in which the user holds the role.
resourceInstanceIdstringNoThe key of a resource instance, such as doc1, to remove a resource role from that instance only. Pass it together with resource_type.
resource_typestringNoThe key of the resource type of the instance, such as document. Pass it together with resourceInstanceId.

If you pass only one of resourceInstanceId and resource_type, UnassignRole throws an ArgumentException before it calls the Permit API.

Example: unassign a role with UnassignRole

The example uses a client named permitClient, created with new Permit(...) as shown in Check permissions with the .NET SDK. userId, roleId, and tenantId hold the keys of the user, the role, and the tenant. UnassignRole returns a Task with no result:

await permitClient.Api.UnassignRole(userId, roleId, tenantId);

UnassignRole return value and errors

UnassignRole returns a Task that completes when the role assignment is removed. The task has no result value.

If the Permit API returns an error, UnassignRole throws a PermitApiException. The exception's StatusCode property has the HTTP status, and its Response property has the response body. The Permit API returns 404 when the user doesn't hold that role in that tenant.