Soenneker.Security.Parsers.BasicAuth.Functions 4.0.31

Prefix Reserved
dotnet add package Soenneker.Security.Parsers.BasicAuth.Functions --version 4.0.31
                    
NuGet\Install-Package Soenneker.Security.Parsers.BasicAuth.Functions -Version 4.0.31
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Security.Parsers.BasicAuth.Functions" Version="4.0.31" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Security.Parsers.BasicAuth.Functions" Version="4.0.31" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Security.Parsers.BasicAuth.Functions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Security.Parsers.BasicAuth.Functions --version 4.0.31
                    
#r "nuget: Soenneker.Security.Parsers.BasicAuth.Functions, 4.0.31"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Security.Parsers.BasicAuth.Functions@4.0.31
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Security.Parsers.BasicAuth.Functions&version=4.0.31
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Security.Parsers.BasicAuth.Functions&version=4.0.31
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Security.Parsers.BasicAuth.Functions

A low-allocation HTTP Basic credential parser for .NET isolated Azure Functions.

Installation

dotnet add package Soenneker.Security.Parsers.BasicAuth.Functions

Usage

The returned spans point into a pooled character buffer. Return that buffer in a finally block after the last credential comparison:

using System.Net;
using System.Security.Cryptography;
using System.Text;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Soenneker.Security.Parsers.BasicAuth.Functions;

[Function("ProtectedEndpoint")]
public HttpResponseData Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData request)
{
    char[]? credentialBuffer = null;

    try
    {
        if (!BasicAuthParser.TryReadBasicCredentials(
                request,
                out ReadOnlySpan<char> username,
                out ReadOnlySpan<char> password,
                out credentialBuffer))
        {
            return request.CreateResponse(HttpStatusCode.Unauthorized);
        }

        bool usernameMatches = username.SequenceEqual(_configuredUsername);
        byte[] suppliedPassword = Encoding.UTF8.GetBytes(password);

        try
        {
            bool passwordMatches = CryptographicOperations.FixedTimeEquals(
                suppliedPassword,
                _configuredPasswordUtf8);

            return request.CreateResponse(
                usernameMatches && passwordMatches
                    ? HttpStatusCode.OK
                    : HttpStatusCode.Unauthorized);
        }
        finally
        {
            CryptographicOperations.ZeroMemory(suppliedPassword);
        }
    }
    finally
    {
        BasicAuthParser.Clear(credentialBuffer);
    }
}

Prepare _configuredPasswordUtf8 outside the request path and protect it like the original secret. Prefer a password hasher or identity provider when the endpoint authenticates user passwords rather than a fixed service credential.

Parsing behavior

  • Reads the first Authorization header value and accepts the Basic scheme case-insensitively.
  • Rejects missing or malformed Base64, headers above 8 KiB, and decoded credentials without a non-empty username and password separated by the first colon.
  • Allows additional colons in the password.
  • Returns spans instead of immutable username/password strings.
  • On success, transfers one rented character buffer to the caller. Call BasicAuthParser.Clear exactly once after using the spans.
  • On failure, clears and returns any rented buffer and leaves the returned buffer value null.

Basic authentication is encoding, not encryption. Use it only over HTTPS, never log the header or decoded credentials, and protect the endpoint with suitable rate limiting and secret rotation.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Security.Parsers.BasicAuth.Functions:

Package Downloads
Soenneker.Validators.BasicAuth.Functions

A validation module for validating HTTP Basic Authentication credentials in Functions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.31 271 8/30/2026
4.0.30 210 8/29/2026
4.0.29 96 8/29/2026
4.0.28 470 7/28/2026
4.0.27 220 7/16/2026
4.0.26 442 6/18/2026
4.0.25 354 6/5/2026
4.0.22 385 4/21/2026
4.0.21 338 3/12/2026
4.0.18 137 3/12/2026
4.0.17 335 3/10/2026
4.0.16 244 3/9/2026
4.0.15 132 3/9/2026
4.0.14 128 3/9/2026
4.0.13 259 3/4/2026
4.0.12 633 1/2/2026
4.0.11 644 11/20/2025
4.0.10 382 11/14/2025
4.0.9 355 11/11/2025
4.0.8 356 11/6/2025
Loading failed

Secure Functions Basic Auth buffer handling