A lightweight and extensible Digest authentication plugin for RestSharp,
implemented as an IAuthenticator.
Install via NuGet:
dotnet add package RestSharp.Authenticators.Digest- .NET Standard 2.0
- .NET Framework 4.7.1+ (limited by RestSharp 114.0.0)
- .NET Core 2.0+
- .NET 5, 6, 7, 8, 9, 10+
- Fully compatible with
RestClientfrom RestSharp
namespace Example
{
using RestSharp;
using RestSharp.Authenticators.Digest;
using System;
public class Program
{
public static void Main(string[] args)
{
var restOptions = new RestClientOptions("https://api.myhost.com/api/v1")
{
Authenticator = new DigestAuthenticator(USERNAME, PASSWORD)
};
var client = new RestClient(restOptions);
var request = new RestRequest("values", Method.GET);
request.AddHeader("Content-Type", "application/json");
var response = client.Execute(request);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Content);
Console.ReadKey(true);
}
}
}- Implements HTTP Digest Authentication with support for both modern and legacy protocols:
- RFC 2617 / RFC 7616 β Full digest authentication with
qop=auth,cnonce, and nonce counting - RFC 2069 β Legacy digest authentication without
qop(for older servers)
- RFC 2617 / RFC 7616 β Full digest authentication with
- Automatic protocol detection β the library reads the server's
WWW-Authenticatechallenge and selects the correct hash format - Nonce, realm, opaque, and qop support
- Compatible with servers that require
WWW-Authenticate: Digest - Stateless and thread-safe
- Works with
RestClientandIRestRequestout of the box
The library automatically detects which protocol the server uses based on the WWW-Authenticate response header. No configuration is needed β the same code works for both protocols.
When the server includes qop in its challenge (e.g., qop="auth" or qop="auth,auth-int"), the library uses the full digest scheme:
response = MD5(MD5(username:realm:password):nonce:nc:cnonce:qop:MD5(method:uri))
The generated Authorization header includes qop, nc, and cnonce fields.
When the server does not include qop in its challenge, the library falls back to the simplified RFC 2069 scheme:
response = MD5(MD5(username:realm:password):nonce:MD5(method:uri))
The generated Authorization header omits qop, nc, and cnonce fields, as required by the legacy protocol.
The usage is identical for both protocols β just create the authenticator and let the library handle the rest:
var restOptions = new RestClientOptions("https://api.myhost.com/api/v1")
{
Authenticator = new DigestAuthenticator("username", "password")
};
var client = new RestClient(restOptions);
var request = new RestRequest("resource");
var response = await client.ExecuteAsync(request);This works transparently whether the server uses RFC 2069 or RFC 2617/7616.
The project includes comprehensive unit and integration tests covering both RFC 2069 and RFC 2617/7616 protocols.
Integration tests use embedded HTTP listeners that simulate digest servers for both protocols.
Tests target multiple frameworks (net8.0, net10.0).
This project is licensed under the MIT License.
Contributions are welcome!
If you find a bug or have an idea for improvement:
- Open an issue
- Or submit a pull request
Please follow the contribution guidelines if available.
Maintained by @thenoobsbr NuGet Package: RestSharp.Authenticators.Digest