Table of Contents

Class RoleManagerExtensions

Namespace
NuvTools.Security.Identity.AspNetCore.Extensions
Assembly
NuvTools.Security.Identity.AspNetCore.dll

Provides extension methods for the RoleManager<TRole> class to simplify the management of claims, particularly permission-based claims, associated with roles.

public static class RoleManagerExtensions
Inheritance
RoleManagerExtensions
Inherited Members

Methods

AddClaimAsync<TRole>(RoleManager<TRole>, TRole, string, string)

Adds a single claim to a role if it does not already exist.

public static Task AddClaimAsync<TRole>(this RoleManager<TRole> roleManager, TRole role, string type, string value) where TRole : class

Parameters

roleManager RoleManager<TRole>

The RoleManager<TRole> instance used to manage roles.

role TRole

The role to which the claim should be added.

type string

The claim type.

value string

The claim value.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TRole

The type representing the application role.

Exceptions

ArgumentNullException

Thrown when roleManager, role, type, or value is null or empty.

AddClaimsAsync<TRole>(RoleManager<TRole>, TRole, IEnumerable<Claim>)

Adds multiple claims to a role.

public static Task AddClaimsAsync<TRole>(this RoleManager<TRole> roleManager, TRole role, IEnumerable<Claim> claims) where TRole : class

Parameters

roleManager RoleManager<TRole>

The RoleManager<TRole> instance used to manage roles.

role TRole

The role to which claims should be added.

claims IEnumerable<Claim>

A collection of claims to add.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TRole

The type representing the application role.

Exceptions

ArgumentNullException

Thrown when roleManager, role, or claims is null.

AddPermissionClaim<TRole>(RoleManager<TRole>, TRole, string)

Adds a single permission claim to a role.

public static Task AddPermissionClaim<TRole>(this RoleManager<TRole> roleManager, TRole role, string value) where TRole : class

Parameters

roleManager RoleManager<TRole>

The RoleManager<TRole> instance used to manage roles.

role TRole

The role to which the permission claim should be added.

value string

The permission value.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TRole

The type representing the application role.

Remarks

This method uses the Permission claim type.

Exceptions

ArgumentNullException

Thrown when roleManager, role, or value is null or empty.

AddPermissionClaims<TRole>(RoleManager<TRole>, TRole, params string[])

Adds multiple permission claims to a role.

public static Task AddPermissionClaims<TRole>(this RoleManager<TRole> roleManager, TRole role, params string[] values) where TRole : class

Parameters

roleManager RoleManager<TRole>

The RoleManager<TRole> instance used to manage roles.

role TRole

The role to which permission claims should be added.

values string[]

An array of permission values to add as claims.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TRole

The type representing the application role.

Exceptions

ArgumentNullException

Thrown when roleManager, role, or values is null or empty.