Class Authenticator
- Namespace
- Cuemon.AspNetCore.Authentication
- Assembly
- Cuemon.AspNetCore.Authentication.dll
Provides a set of static methods for working with HTTP based authentication.
public static class Authenticator
- Inheritance
-
Authenticator
Methods
Authenticate<T>(HttpContext, Boolean, Func<HttpContext, String, T>, TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, Boolean>)
Provides a generic way to make authentication requests using the specified context
.
public static ConditionalValue<ClaimsPrincipal> Authenticate<T>(HttpContext context, bool requireSecureConnection, Func<HttpContext, string, T> authorizationParser, TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, bool> principalParser)
Parameters
context
HttpContextThe context of the ASP.NET application.
requireSecureConnection
BooleanWhen
true
, the HTTP connection is required to use secure sockets (that is, HTTPS); whenfalse
no requirement is enforced.authorizationParser
Func<HttpContext, String, T>The function delegate that will parse the authorization header of a web request and return the credentials of
T
.principalParser
TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, Boolean>The function delegate that will parse the credentials of
T
returned fromauthorizationParser
and if successful returns a ClaimsPrincipal object.
Returns
- ConditionalValue<ClaimsPrincipal>
A ClaimsPrincipal if
principalParser
was successful.
Type Parameters
T
The type of the credentials returned from
authorizationParser
and passed toprincipalParser
.
Exceptions
- SecurityException
Authorized failed for the request.
TryAuthenticate<T>(HttpContext, Boolean, Func<HttpContext, String, T>, TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, Boolean>, out ConditionalValue<ClaimsPrincipal>)
Provides a generic way to make authentication requests using the specified context
.
public static bool TryAuthenticate<T>(HttpContext context, bool requireSecureConnection, Func<HttpContext, string, T> authorizationParser, TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, bool> principalParser, out ConditionalValue<ClaimsPrincipal> principal)
Parameters
context
HttpContextThe context of the ASP.NET application.
requireSecureConnection
BooleanWhen
true
, the HTTP connection is required to use secure sockets (that is, HTTPS); whenfalse
no requirement is enforced.authorizationParser
Func<HttpContext, String, T>The function delegate that will parse the authorization header of a web request and return the credentials of
T
.principalParser
TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, Boolean>The function delegate that will parse the credentials of
T
returned fromauthorizationParser
and if successful returns a ClaimsPrincipal object.principal
ConditionalValue<ClaimsPrincipal>The ClaimsPrincipal of the authenticated user if the authentication was successful.
Returns
- Boolean
true
if the specified parameters triggers a successful authentication; otherwise,false
.
Type Parameters
T
The type of the credentials returned from
authorizationParser
and passed toprincipalParser
.