Table of Contents

Class BasicAuthenticationMiddlewareExtension

Namespace
Arc4u.OAuth2.Middleware
Assembly
Arc4u.OAuth2.AspNetCore.dll

Registers and configures the BasicAuthenticationMiddleware.

public static class BasicAuthenticationMiddlewareExtension
Inheritance
BasicAuthenticationMiddlewareExtension
Inherited Members

Methods

AddBasicAuthenticationSettings(IServiceCollection, IConfiguration, string, IX509CertificateLoader?, bool)

Registers the Basic authentication settings from a configuration section. The section is bound to BasicAuthenticationConfigurationSectionOptions, which points to the sections holding the BasicSettingsOptions and the certificates used to decrypt the credentials sent in headers.

public static void AddBasicAuthenticationSettings(this IServiceCollection services, IConfiguration configuration, string sectionName = "Authentication:Basic", IX509CertificateLoader? certificateLoader = null, bool throwExceptionIfSectionDoesntExist = true)

Parameters

services IServiceCollection

The service collection.

configuration IConfiguration

The configuration.

sectionName string

The section to bind. The default is Authentication:Basic.

certificateLoader IX509CertificateLoader

The loader of the certificates. When null, a default X509CertificateLoader is used.

throwExceptionIfSectionDoesntExist bool

true to throw when the section does not exist; otherwise nothing is registered.

Examples

builder.Services.AddBasicAuthenticationSettings(builder.Configuration);

Exceptions

ConfigurationException

The section is missing (and throwExceptionIfSectionDoesntExist is true) or a mandatory value is empty.

AddBasicAuthenticationSettings(IServiceCollection, Action<BasicAuthenticationConfigurationOptions>)

Registers the Basic authentication settings from code.

public static void AddBasicAuthenticationSettings(this IServiceCollection services, Action<BasicAuthenticationConfigurationOptions> options)

Parameters

services IServiceCollection

The service collection.

options Action<BasicAuthenticationConfigurationOptions>

The action that configures the settings.

Exceptions

ConfigurationException

The default UPN suffix or a certificate header is invalid, or a mandatory value of the Basic settings is empty.

BuildBasics(Action<BasicSettingsOptions>)

Validates the BasicSettingsOptions and converts them into the key/value settings read by the token providers.

public static SimpleKeyValueSettings BuildBasics(this Action<BasicSettingsOptions> options)

Parameters

options Action<BasicSettingsOptions>

The action that configures the BasicSettingsOptions.

Returns

SimpleKeyValueSettings

The settings (see TokenKeys). Multiple scopes are separated by a space.

Exceptions

ConfigurationException

ProviderId, ClientId, AuthenticationType or the scopes are missing.

RegisterBasicAuthority(IServiceCollection, Action<BasicSettingsOptions>)

Registers the authority of the Basic settings, when there is one, as the named authority Basic.

public static bool RegisterBasicAuthority(IServiceCollection services, Action<BasicSettingsOptions> options)

Parameters

services IServiceCollection

The service collection.

options Action<BasicSettingsOptions>

The action that configures the BasicSettingsOptions.

Returns

bool

true when the settings define an authority and it has been registered.

UseBasicAuthentication(IApplicationBuilder)

Adds the BasicAuthenticationMiddleware to the request pipeline. It must run before the authentication middleware.

public static IApplicationBuilder UseBasicAuthentication(this IApplicationBuilder app)

Parameters

app IApplicationBuilder

The application builder.

Returns

IApplicationBuilder

The application builder, to chain calls.

Examples

builder.Services.AddBasicAuthenticationSettings(builder.Configuration);
// ...
app.UseBasicAuthentication();
app.UseAuthentication();

Exceptions

ArgumentNullException

app is null.