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
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration.
sectionNamestringThe section to bind. The default is
Authentication:Basic.certificateLoaderIX509CertificateLoaderThe loader of the certificates. When null, a default
X509CertificateLoaderis used.throwExceptionIfSectionDoesntExistbooltrue 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
throwExceptionIfSectionDoesntExistis 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
servicesIServiceCollectionThe service collection.
optionsAction<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
optionsAction<BasicSettingsOptions>The action that configures the BasicSettingsOptions.
Returns
- SimpleKeyValueSettings
The settings (see TokenKeys). Multiple scopes are separated by a space.
Exceptions
- ConfigurationException
ProviderId,ClientId,AuthenticationTypeor 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
servicesIServiceCollectionThe service collection.
optionsAction<BasicSettingsOptions>The action that configures the BasicSettingsOptions.
Returns
UseBasicAuthentication(IApplicationBuilder)
Adds the BasicAuthenticationMiddleware to the request pipeline. It must run before the authentication middleware.
public static IApplicationBuilder UseBasicAuthentication(this IApplicationBuilder app)
Parameters
appIApplicationBuilderThe application builder.
Returns
- IApplicationBuilder
The application builder, to chain calls.
Examples
builder.Services.AddBasicAuthenticationSettings(builder.Configuration);
// ...
app.UseBasicAuthentication();
app.UseAuthentication();
Exceptions
- ArgumentNullException
appis null.