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
roleManagerRoleManager<TRole>The RoleManager<TRole> instance used to manage roles.
roleTRoleThe role to which the claim should be added.
typestringThe claim type.
valuestringThe claim value.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TRoleThe type representing the application role.
Exceptions
- ArgumentNullException
Thrown when
roleManager,role,type, orvalueis 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
roleManagerRoleManager<TRole>The RoleManager<TRole> instance used to manage roles.
roleTRoleThe role to which claims should be added.
claimsIEnumerable<Claim>A collection of claims to add.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TRoleThe type representing the application role.
Exceptions
- ArgumentNullException
Thrown when
roleManager,role, orclaimsis 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
roleManagerRoleManager<TRole>The RoleManager<TRole> instance used to manage roles.
roleTRoleThe role to which the permission claim should be added.
valuestringThe permission value.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TRoleThe type representing the application role.
Remarks
This method uses the Permission claim type.
Exceptions
- ArgumentNullException
Thrown when
roleManager,role, orvalueis 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
roleManagerRoleManager<TRole>The RoleManager<TRole> instance used to manage roles.
roleTRoleThe role to which permission claims should be added.
valuesstring[]An array of permission values to add as claims.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TRoleThe type representing the application role.
Exceptions
- ArgumentNullException
Thrown when
roleManager,role, orvaluesis null or empty.