AuthenticationHandler<TOptions> Class

Base class for the per-request work performed by most authentication middleware.

Namespace
Microsoft.AspNetCore.Authentication
Assemblies
  • Microsoft.AspNetCore.Authentication

Syntax

public abstract class AuthenticationHandler<TOptions> : IAuthenticationHandler where TOptions : AuthenticationOptions
class Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>

Methods

AuthenticateAsync(Microsoft.AspNetCore.Http.Features.Authentication.AuthenticateContext)
Return type:System.Threading.Tasks.Task
public Task AuthenticateAsync(AuthenticateContext context)
BuildRedirectUri(System.String)
Return type:System.String
protected string BuildRedirectUri(string targetPath)
ChallengeAsync(Microsoft.AspNetCore.Http.Features.Authentication.ChallengeContext)
Return type:System.Threading.Tasks.Task
public Task ChallengeAsync(ChallengeContext context)
FinishResponseAsync()

Hook that is called when the response about to be sent

Return type:System.Threading.Tasks.Task
protected virtual Task FinishResponseAsync()
GetDescriptions(Microsoft.AspNetCore.Http.Features.Authentication.DescribeSchemesContext)
public void GetDescriptions(DescribeSchemesContext describeContext)
HandleAuthenticateAsync()
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult>
protected abstract Task<AuthenticateResult> HandleAuthenticateAsync()
HandleAuthenticateOnceAsync()
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult>
protected Task<AuthenticateResult> HandleAuthenticateOnceAsync()
HandleForbiddenAsync(Microsoft.AspNetCore.Http.Features.Authentication.ChallengeContext)
Return type:System.Threading.Tasks.Task<System.Boolean>
protected virtual Task<bool> HandleForbiddenAsync(ChallengeContext context)
HandleRequestAsync()

Called once by common code after initialization. If an authentication middleware responds directly to specifically known paths it must override this virtual, compare the request path to it’s known paths, provide any response information as appropriate, and true to stop further processing.

Return type:System.Threading.Tasks.Task<System.Boolean>
Returns:Returning false will cause the common code to call the next middleware in line. Returning true will cause the common code to begin the async completion journey without calling the rest of the middleware pipeline.
public virtual Task<bool> HandleRequestAsync()
HandleSignInAsync(Microsoft.AspNetCore.Http.Features.Authentication.SignInContext)
Return type:System.Threading.Tasks.Task
protected virtual Task HandleSignInAsync(SignInContext context)
HandleSignOutAsync(Microsoft.AspNetCore.Http.Features.Authentication.SignOutContext)
Return type:System.Threading.Tasks.Task
protected virtual Task HandleSignOutAsync(SignOutContext context)
HandleUnauthorizedAsync(Microsoft.AspNetCore.Http.Features.Authentication.ChallengeContext)

Override this method to deal with 401 challenge concerns, if an authentication scheme in question deals an authentication interaction as part of it’s request flow. (like adding a response header, or changing the 401 result to 302 of a login page or external sign-in location.)

Return type:System.Threading.Tasks.Task<System.Boolean>
Returns:True if no other handlers should be called
protected virtual Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
InitializeAsync(TOptions, Microsoft.AspNetCore.Http.HttpContext, Microsoft.Extensions.Logging.ILogger, System.Text.Encodings.Web.UrlEncoder)

Initialize is called once per request to contextualize this instance with appropriate state.

Arguments:
  • options (TOptions) – The original options passed by the application control behavior
  • context (Microsoft.AspNetCore.Http.HttpContext) – The utility object to observe the current request and response
  • logger (Microsoft.Extensions.Logging.ILogger) – The logging factory used to create loggers
  • encoder (System.Text.Encodings.Web.UrlEncoder) – The Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.UrlEncoder.
Return type:

System.Threading.Tasks.Task

Returns:

async completion

public Task InitializeAsync(TOptions options, HttpContext context, ILogger logger, UrlEncoder encoder)
ShouldHandleScheme(System.String, System.Boolean)
Return type:System.Boolean
public bool ShouldHandleScheme(string authenticationScheme, bool handleAutomatic)
SignInAsync(Microsoft.AspNetCore.Http.Features.Authentication.SignInContext)
Return type:System.Threading.Tasks.Task
public Task SignInAsync(SignInContext context)
SignOutAsync(Microsoft.AspNetCore.Http.Features.Authentication.SignOutContext)
Return type:System.Threading.Tasks.Task
public Task SignOutAsync(SignOutContext context)

Properties

Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.ChallengeCalled
Return type:System.Boolean
protected bool ChallengeCalled { get; set; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.Context
Return type:Microsoft.AspNetCore.Http.HttpContext
protected HttpContext Context { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.CurrentUri
Return type:System.String
protected string CurrentUri { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.Logger
Return type:Microsoft.Extensions.Logging.ILogger
protected ILogger Logger { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.Options
Return type:TOptions
protected TOptions Options { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.OriginalPath
Return type:Microsoft.AspNetCore.Http.PathString
protected PathString OriginalPath { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.OriginalPathBase
Return type:Microsoft.AspNetCore.Http.PathString
protected PathString OriginalPathBase { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.PriorHandler
Return type:Microsoft.AspNetCore.Http.Features.Authentication.IAuthenticationHandler
public IAuthenticationHandler PriorHandler { get; set; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.Request
Return type:Microsoft.AspNetCore.Http.HttpRequest
protected HttpRequest Request { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.Response
Return type:Microsoft.AspNetCore.Http.HttpResponse
protected HttpResponse Response { get; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.SignInAccepted
Return type:System.Boolean
protected bool SignInAccepted { get; set; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.SignOutAccepted
Return type:System.Boolean
protected bool SignOutAccepted { get; set; }
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.UrlEncoder
Return type:System.Text.Encodings.Web.UrlEncoder
protected UrlEncoder UrlEncoder { get; }