Table of Contents

TryAuthenticate Method

Definition

Namespace
Cuemon.AspNetCore.Authentication
Assemblies
Cuemon.AspNetCore.Authentication.dll
Source
src/Cuemon.AspNetCore.Authentication/Authenticator.cs

TryAuthenticate<T>(HttpContext, bool, Func<HttpContext, string, T>, TesterFunc<HttpContext, T, ConditionalValue<ClaimsPrincipal>, bool>, 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 HttpContext

The context of the ASP.NET application.

requireSecureConnection bool

When true, the HTTP connection is required to use secure sockets (that is, HTTPS); when false 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>, bool>

The function delegate that will parse the credentials of T returned from authorizationParser and if successful returns a ClaimsPrincipal object.

principal ConditionalValue<ClaimsPrincipal>

The ClaimsPrincipal of the authenticated user if the authentication was successful.

Returns

bool

true if the specified parameters triggers a successful authentication; otherwise, false.

Type Parameters

T

The type of the credentials returned from authorizationParser and passed to principalParser.