Table of Contents

DigestAuthenticator Delegate

Definition

Namespace
Cuemon.AspNetCore.Authentication.Digest
Assemblies
Cuemon.AspNetCore.Authentication.dll
Source
src/Cuemon.AspNetCore.Authentication/Digest/DigestAuthenticator.cs

Represents the method that defines an Authenticator typically assigned on DigestAuthenticationOptions.

public delegate ClaimsPrincipal DigestAuthenticator(string username, out string password)

Parameters

username string

The username to match and lookup the paired password.

password string

The password paired with username.

Returns

ClaimsPrincipal

A ClaimsPrincipal that is associated with the result of password.

Examples

The following example demonstrates how to assign and invoke a delegate when a digest-auth username resolves to a stored password.

using System;
using System.Security.Claims;
using Cuemon.AspNetCore.Authentication.Digest;

namespace MyApp.Examples;

public static class DigestAuthenticatorExample
{
    public static void Demonstrate()
    {
        DigestAuthenticator 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));
        };

        var principal = authenticator("Agent", out var password);

        Console.WriteLine(password);
        Console.WriteLine(principal?.Identity?.Name);
    }
}