Table of Contents

Class CookieAuthenticationExtensions

Namespace
Arc4u.Blazor.Options
Assembly
Arc4u.OAuth2.Blazor.dll

Provides extension methods to register and configure AuthenticationCookieSettingsOption for handling authentication cookies. Options can be configured directly from application configuration or via custom code using an action delegate.

public static class CookieAuthenticationExtensions
Inheritance
CookieAuthenticationExtensions
Inherited Members

Methods

AddAuthenticationCookie(IServiceCollection, IConfiguration, string, string)

Registers the cookie authentication of a Blazor WebAssembly application from a configuration section. See the other overload for the registered services.

public static void AddAuthenticationCookie(this IServiceCollection services, IConfiguration configuration, string sectionName = "Authentication:OAuth2.Settings", string sectionKey = "OAuth2")

Parameters

services IServiceCollection

The service collection.

configuration IConfiguration

The configuration.

sectionName string

The section holding the AuthenticationCookieSettingsOption. The default is Authentication:OAuth2.Settings.

sectionKey string

The name of the key/value settings. The default is OAuth2.

Examples

builder.Services.AddAuthenticationCookie(builder.Configuration);

Exceptions

ArgumentException

The section does not exist.

MissingFieldException

A mandatory value of the options is empty.

AddAuthenticationCookie(IServiceCollection, Action<AuthenticationCookieSettingsOption>, string)

Registers the cookie authentication of a Blazor WebAssembly application from code. The settings are registered as the key/value settings sectionKey and an HttpClient named HttpClientName is added, whose requests include the browser cookies (see AttachCookiesHandler).

public static void AddAuthenticationCookie(this IServiceCollection services, Action<AuthenticationCookieSettingsOption> option, string sectionKey = "OAuth2")

Parameters

services IServiceCollection

The service collection.

option Action<AuthenticationCookieSettingsOption>

The action that configures the AuthenticationCookieSettingsOption.

sectionKey string

The name of the key/value settings. The default is OAuth2.

Examples

builder.Services.AddAuthenticationCookie(options =>
{
    options.BaseUri = new Uri(builder.HostEnvironment.BaseAddress);
    options.TokenRequestUrl = "/authentication/token";
});

Exceptions

MissingFieldException

A mandatory value of the options is empty.

ReadAuthenticationCookieSettingsOption(IServiceCollection, IConfiguration, string)

Builds and validates the AuthenticationCookieSettingsOption from a configuration section.

public static AuthenticationCookieSettingsOption ReadAuthenticationCookieSettingsOption(this IServiceCollection services, IConfiguration configuration, string sectionName = "Authentication:OAuth2.Settings")

Parameters

services IServiceCollection

The service collection.

configuration IConfiguration

The configuration.

sectionName string

The section holding the options. The default is Authentication:OAuth2.Settings, as for AddAuthenticationCookie.

Returns

AuthenticationCookieSettingsOption

The validated options.

Exceptions

ArgumentNullException

sectionName is empty or configuration is null.

ArgumentException

The section does not exist.

MissingFieldException

The client name, provider id, token request url or base uri is empty.

ReadAuthenticationCookieSettingsOption(IServiceCollection, Action<AuthenticationCookieSettingsOption>)

Builds and validates the AuthenticationCookieSettingsOption from code.

public static AuthenticationCookieSettingsOption ReadAuthenticationCookieSettingsOption(this IServiceCollection services, Action<AuthenticationCookieSettingsOption> option)

Parameters

services IServiceCollection

The service collection.

option Action<AuthenticationCookieSettingsOption>

The action that configures the options.

Returns

AuthenticationCookieSettingsOption

The validated options.

Exceptions

MissingFieldException

The client name, provider id, token request url or base uri is empty.