Class CookieAuthenticationExtensions
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
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration.
sectionNamestringThe section holding the AuthenticationCookieSettingsOption. The default is
Authentication:OAuth2.Settings.sectionKeystringThe 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
servicesIServiceCollectionThe service collection.
optionAction<AuthenticationCookieSettingsOption>The action that configures the AuthenticationCookieSettingsOption.
sectionKeystringThe 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
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration.
sectionNamestringThe section holding the options. The default is
Authentication:OAuth2.Settings, as forAddAuthenticationCookie.
Returns
- AuthenticationCookieSettingsOption
The validated options.
Exceptions
- ArgumentNullException
sectionNameis empty orconfigurationis 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
servicesIServiceCollectionThe service collection.
optionAction<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.