DigestAuthenticationHandler Class
Definition
- Namespace
- Cuemon.AspNetCore.Authentication.Digest
- Assemblies
- Cuemon.AspNetCore.Authentication.dll
Provides a HTTP Digest Access Authentication implementation of AuthenticationHandler<TOptions> for ASP.NET Core.
public class DigestAuthenticationHandler : AuthenticationHandler<DigestAuthenticationOptions>, IAuthenticationHandler
- Inheritance
-
DigestAuthenticationHandler
- Implements
- Inherited Members
Examples
The following example demonstrates how to register DigestAuthenticationHandler with ASP.NET Core authentication services. It configures DI with INonceTracker, registers a digest authentication scheme with a username/password lookup callback, and builds the service provider. The handler is then resolved from DI and its configured realm is written to the console, verifying that digest authentication wiring is operational.
using System;
using System.Security.Claims;
using Cuemon.AspNetCore.Authentication;
using Cuemon.AspNetCore.Authentication.Digest;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
namespace MyApp.Examples;
public static class DigestAuthenticationHandlerExample
{
public static void Demonstrate()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddSingleton<INonceTracker, MemoryNonceTracker>();
services.AddAuthentication(DigestAuthorizationHeader.Scheme)
.AddScheme<DigestAuthenticationOptions, DigestAuthenticationHandler>(DigestAuthorizationHeader.Scheme, options =>
{
options.Realm = "docs-example";
options.RequireSecureConnection = false;
options.Authenticator = (string username, out string password) =>
{
password = username == "Agent" ? "Test" : null;
return password == null
? null
: new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, username) }, DigestAuthorizationHeader.Scheme));
};
});
using var provider = services.BuildServiceProvider();
var handler = provider.GetRequiredService<DigestAuthenticationHandler>();
Console.WriteLine($"Authentication realm: {handler.Options.Realm}");
}
}
Constructors
| Name | Description |
|---|---|
| DigestAuthenticationHandler(IOptionsMonitor<DigestAuthenticationOptions>, ILoggerFactory, UrlEncoder, INonceTracker) | Initializes a new instance of the DigestAuthenticationHandler class. |
Methods
| Name | Description |
|---|---|
| HandleAuthenticateAsync() | Handle authenticate as an asynchronous operation. |
| HandleChallengeAsync(AuthenticationProperties) | Handle challenge as an asynchronous operation. |
See Also
AuthenticationHandler<TOptions>