Unosquare
    Show / Hide Table of Contents

    Class AuthenticationModuleBase

    Base class for authentication modules.

    Inheritance
    Object
    WebModuleBase
    AuthenticationModuleBase
    BasicAuthenticationModuleBase
    Implements
    IWebModuleImpl
    IWebModule
    Inherited Members
    WebModuleBase.Container
    WebModuleBase.IWebModuleImpl.SetContainer(IWebModuleContainer)
    WebModuleBase.BaseRoute
    WebModuleBase.OnUnhandledException
    WebModuleBase.OnHttpException
    WebModuleBase.LogSource
    WebModuleBase.Start(CancellationToken)
    WebModuleBase.MatchUrlPath(String)
    WebModuleBase.HandleRequestAsync(IHttpContext)
    WebModuleBase.OnStart(CancellationToken)
    WebModuleBase.SetContainer(IWebModuleContainer)
    Namespace: EmbedIO.Authentication
    Syntax
    public abstract class AuthenticationModuleBase : WebModuleBase, IWebModuleImpl, IWebModule

    Constructors

    AuthenticationModuleBase(String)

    Initializes a new instance of the AuthenticationModuleBase class.

    Declaration
    protected AuthenticationModuleBase(string baseRoute)
    Parameters
    Type Name Description
    String baseRoute

    The base route served by this module.

    Properties

    IsFinalHandler

    Gets a value indicating whether processing of a request should stop after a module has handled it.

    Declaration
    public override sealed bool IsFinalHandler { get; }
    Property Value
    Type Description
    Boolean
    Overrides
    WebModuleBase.IsFinalHandler
    Remarks

    Authentication modules, i.e. modules derived from AuthenticationModuleBase, always have this property set to false.

    See Also
    IsHandled
    SetHandled()

    OnInvalidCredentials

    Gets or sets an AuthenticationHandlerCallback that is called if a request contains invalid credentials.

    The default is Unauthorized(IHttpContext, AuthenticationModuleBase).

    Declaration
    public AuthenticationHandlerCallback OnInvalidCredentials { get; set; }
    Property Value
    Type Description
    AuthenticationHandlerCallback
    See Also
    AuthenticateAsync(IHttpContext)
    OnMissingCredentials
    AuthenticationHandler

    OnMissingCredentials

    Gets or sets an AuthenticationHandlerCallback that is called if authentication could not take place. For example, BasicAuthenticationModuleBase calls this handler if the request has no Authorization header.

    The default is Unauthorized(IHttpContext, AuthenticationModuleBase).

    Declaration
    public AuthenticationHandlerCallback OnMissingCredentials { get; set; }
    Property Value
    Type Description
    AuthenticationHandlerCallback
    See Also
    AuthenticateAsync(IHttpContext)
    OnInvalidCredentials
    AuthenticationHandler

    Methods

    AuthenticateAsync(IHttpContext)

    Asynchronously authenticates a user, based on a request's contents, yielding an interface that will be assigned to the HTTP context's User property for use by other modules.

    Declaration
    protected abstract Task<IPrincipal> AuthenticateAsync(IHttpContext context)
    Parameters
    Type Name Description
    IHttpContext context

    The HTTP context of the request.

    Returns
    Type Description
    Task<IPrincipal>

    A whose result will be as follows:

    If authentication did not take place (for example, in the case of BasicAuthenticationModuleBase, when the request has no Authorization header)An interface, whose Identity property has both its Name and AuthenticationType properties set to the empty string. Returning NoUser is the fastest way in this case.
    If the request contains INVALID credentialsAn interface, whose Identity property has its Name property set to the empty string, and its AuthenticationType property set to a non-empty string. NoUser cannot be returned in this case.
    If the request contains VALID credentialsAn interface, whose Identity property has both its Name and AuthenticationType properties set to non-empty strings.

    Remarks

    this method will not be called if the property assigned to the User property of context has an Identity with a non-empty AuthenticationType.

    This way, two or more authentication modules may be added to a WebServer. The first one that succeeds in retrieving user credentials from the request, whether valid or not, will cause subsequent authentication modules to skip processing the HTTP context completely.

    OnRequestAsync(IHttpContext)

    Called to handle a request from a client.

    Declaration
    protected override sealed Task OnRequestAsync(IHttpContext context)
    Parameters
    Type Name Description
    IHttpContext context

    The context of the request being handled.

    Returns
    Type Description
    Task

    A representing the ongoing operation.

    Overrides
    WebModuleBase.OnRequestAsync(IHttpContext)

    Implements

    IWebModuleImpl
    IWebModule

    Comments

    Back to top Copyright © 2017-2019 Unosquare