Digest Authentication with RestSharp

Since RestSharp does not provide an authenticator for Digest Authentication, I simple wrote one that works for me.

Usage

var client =
    new RestClient(@"http://yourserver.com/api")
    {
        Authenticator = new DigestAuthenticator(userName, password)
    };

Implementation

The class is rather simple:

public class DigestAuthenticator : 
    IAuthenticator
{
    private readonly string _user;
    private readonly string _pass;

    public DigestAuthenticator(string user, string pass)
    {
        _user = user;
        _pass = pass;
    }

    public void Authenticate(
        IRestClient client, IRestRequest request)
    {
        request.Credentials = new NetworkCredential(_user, _pass);
    }
}

Enjoy! 🙂