Class AuthExtensions
a set of auth related extensions
Inherited Members
Namespace: FastEndpoints.Security
Assembly: FastEndpoints.Security.dll
Syntax
public static class AuthExtensions
Methods
Add(List<Claim>, params Claim[])
adds multiple Claims to the list.
Declaration
public static void Add(this List<Claim> list, params Claim[] claims)
Parameters
Type | Name | Description |
---|---|---|
List<Claim> | list | |
Claim[] | claims | the Claims to append to the list. |
Add(List<Claim>, params (string claimType, string claimValue)[])
adds multiple Claims to the list.
Declaration
public static void Add(this List<Claim> list, params (string claimType, string claimValue)[] claims)
Parameters
Type | Name | Description |
---|---|---|
List<Claim> | list | |
(string claimType, string claimValue)[] | claims | the claim |
Add(List<string>, params string[])
adds multiple strings to a list.
Declaration
public static void Add(this List<string> list, params string[] values)
Parameters
Type | Name | Description |
---|---|---|
List<string> | list | |
string[] | values | the strings to append to the list. |
AddCookieAuth(IServiceCollection, TimeSpan, Action<CookieAuthenticationOptions>?)
configure and enable cookie based authentication
Declaration
public static IServiceCollection AddCookieAuth(this IServiceCollection services, TimeSpan validFor, Action<CookieAuthenticationOptions>? options = null)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | |
TimeSpan | validFor | specify how long the created cookie is valid for with a TimeSpan |
Action<CookieAuthenticationOptions> | options | optional action for configuring cookie authentication options |
Returns
Type | Description |
---|---|
IServiceCollection |
AddJWTBearerAuth(IServiceCollection, string, TokenSigningStyle, Action<JwtBearerOptions>?)
configure and enable jwt bearer authentication
Declaration
public static IServiceCollection AddJWTBearerAuth(this IServiceCollection services, string tokenSigningKey, JWTBearer.TokenSigningStyle tokenSigningStyle, Action<JwtBearerOptions>? jwtOptions = null)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | |
string | tokenSigningKey | the secret key to use for verifying the jwt tokens |
JWTBearer.TokenSigningStyle | tokenSigningStyle | specify the token signing style |
Action<JwtBearerOptions> | jwtOptions | configuration action to specify options for the authentication scheme |
Returns
Type | Description |
---|---|
IServiceCollection |
AddJWTBearerAuth(IServiceCollection, string, TokenSigningStyle, Action<TokenValidationParameters>?, Action<JwtBearerEvents>?)
configure and enable jwt bearer authentication
Declaration
public static IServiceCollection AddJWTBearerAuth(this IServiceCollection services, string tokenSigningKey, JWTBearer.TokenSigningStyle tokenSigningStyle = TokenSigningStyle.Symmetric, Action<TokenValidationParameters>? tokenValidation = null, Action<JwtBearerEvents>? bearerEvents = null)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | |
string | tokenSigningKey | the secret key to use for verifying the jwt tokens |
JWTBearer.TokenSigningStyle | tokenSigningStyle | specify the token signing style |
Action<TokenValidationParameters> | tokenValidation | configuration action to specify additional token validation parameters |
Action<JwtBearerEvents> | bearerEvents | configuration action to specify custom jwt bearer events |
Returns
Type | Description |
---|---|
IServiceCollection |
AddJWTBearerAuth(IServiceCollection, string, Action<JwtBearerOptions>)
configure and enable jwt bearer authentication
Declaration
public static IServiceCollection AddJWTBearerAuth(this IServiceCollection services, string tokenSigningKey, Action<JwtBearerOptions> jwtOptions)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | |
string | tokenSigningKey | the secret key to use for verifying the jwt tokens |
Action<JwtBearerOptions> | jwtOptions | configuration action to specify options for the authentication scheme |
Returns
Type | Description |
---|---|
IServiceCollection |
ClaimValue(ClaimsPrincipal, string)
get the claim value for a given claim type of the current user principal. if the user doesn't have the requested claim type, a null will be returned.
Declaration
public static string? ClaimValue(this ClaimsPrincipal principal, string claimType)
Parameters
Type | Name | Description |
---|---|---|
ClaimsPrincipal | principal | |
string | claimType | the claim type to look for |
Returns
Type | Description |
---|---|
string |
HasClaimType(ClaimsPrincipal, string)
determines if the current user principal has the given claim type
Declaration
public static bool HasClaimType(this ClaimsPrincipal principal, string claimType)
Parameters
Type | Name | Description |
---|---|---|
ClaimsPrincipal | principal | |
string | claimType | the claim type to check for |
Returns
Type | Description |
---|---|
bool |
HasPermission(ClaimsPrincipal, string)
returns true of the current user principal has a given permission code.
Declaration
public static bool HasPermission(this ClaimsPrincipal principal, string permissionCode)
Parameters
Type | Name | Description |
---|---|---|
ClaimsPrincipal | principal | |
string | permissionCode | the permission code to check for |
Returns
Type | Description |
---|---|
bool |