Table of Contents

DigestAuthorizationHeaderBuilder Class

Definition

Provides a way to fluently represent a HTTP Digest Access Authentication header.

public class DigestAuthorizationHeaderBuilder : AuthorizationHeaderBuilder<DigestAuthorizationHeader, DigestAuthorizationHeaderBuilder>
Inheritance
DigestAuthorizationHeaderBuilder
Inherited Members

Examples

The following example demonstrates how to build a Digest access authorization header from a challenge header.

using System;
using Cuemon.AspNetCore.Authentication.Digest;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;

namespace MyApp.Examples;

public static class DigestAuthorizationHeaderBuilderExample
{
    public static void Demonstrate()
    {
        var headers = new HeaderDictionary
        {
            [HeaderNames.WWWAuthenticate] = "Digest realm=\"docs-example\", qop=\"auth, auth-int\", nonce=\"abc123\", opaque=\"opaque456\", stale=false, algorithm=SHA-256"
        };

        var builder = new DigestAuthorizationHeaderBuilder(DigestCryptoAlgorithm.Sha256)
            .AddRealm("docs-example")
            .AddUserName("Agent")
            .AddUri("/resource")
            .AddNc(1)
            .AddCnonce("client-nonce")
            .AddQopAuthentication()
            .AddFromWwwAuthenticateHeader(headers)
            .AddResponse("Test", "GET");

        var header = builder.Build();

        Console.WriteLine(header.ToString());
    }
}

Constructors

Name Description
DigestAuthorizationHeaderBuilder()

Initializes a new instance of the DigestAuthorizationHeaderBuilder class.

DigestAuthorizationHeaderBuilder(DigestCryptoAlgorithm)

Initializes a new instance of the DigestAuthorizationHeaderBuilder class.

Properties

Name Description
DigestAlgorithm

Gets the algorithm of the HTTP Digest Access Authentication.

Methods

Name Description
AddCnonce(string)

Associates the ClientNonce field with the specified clientNonce.

AddFromDigestAuthorizationHeader(DigestAuthorizationHeader)

Associates any Digest fields found in the HTTP Authorization header from the specified header.

AddFromWwwAuthenticateHeader(IHeaderDictionary)

Associates any Digest fields found in the HTTP WWW-Authenticate header from the specified headers.

AddFromWwwAuthenticateHeader(HttpResponseHeaders)

Associates any Digest fields found in the HTTP WWW-Authenticate header from the specified headers.

AddNc(int)

Associates the NonceCount field with the specified nonceCount.

AddQopAuthentication()

Associates the QualityOfProtection field with "auth".

AddQopAuthenticationIntegrity()

Associates the QualityOfProtection field with "auth-int".

AddRealm(string)

Associates the Realm field with the specified realm.

AddResponse(string, string, string)

Associates the Response field with the computed values of ComputeHash1(string), ComputeHash2(string, string) and ComputeResponse(string, string).

AddUri(string)

Associates the DigestUri field with the specified digestUri.

AddUserName(string)

Associates the UserName field with the specified username.

Build()

Returns a string that represents this instance.

ComputeHash1(string)

Computes a by parameter defined UnkeyedCryptoAlgorithm hash value of the required values for the HTTP Digest access authentication HA1.

ComputeHash2(string, string)

Computes a by parameter defined UnkeyedCryptoAlgorithm hash value of the required values for the HTTP Digest access authentication HA2.

ComputeResponse(string, string)

Computes a by parameter defined UnkeyedCryptoAlgorithm hash value of the required values for the HTTP Digest access authentication RESPONSE.