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
<PackageReference Include="Soenneker.Security.Parsers.BasicAuth.Functions" Version="4.0.31" />
<PackageVersion Include="Soenneker.Security.Parsers.BasicAuth.Functions" Version="4.0.31" />
<PackageReference Include="Soenneker.Security.Parsers.BasicAuth.Functions" />
paket add Soenneker.Security.Parsers.BasicAuth.Functions --version 4.0.31
#r "nuget: Soenneker.Security.Parsers.BasicAuth.Functions, 4.0.31"
#:package Soenneker.Security.Parsers.BasicAuth.Functions@4.0.31
#addin nuget:?package=Soenneker.Security.Parsers.BasicAuth.Functions&version=4.0.31
#tool nuget:?package=Soenneker.Security.Parsers.BasicAuth.Functions&version=4.0.31
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
Authorizationheader value and accepts theBasicscheme 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.Clearexactly 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 | Versions 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. |
-
net10.0
- Microsoft.Azure.Functions.Worker.Core (>= 2.52.0)
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 |
Secure Functions Basic Auth buffer handling