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! 🙂

2 Gedanken zu „Digest Authentication with RestSharp

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.