Magerquark.de

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

Kommentare

2 Kommentare zu „Digest Authentication with RestSharp“

  1. […] write your own implementation of IAuthenticator. The Internet was my friend again as I found this link which gave the simplest implementation of digest authentication for Restsharp imaginable. These few […]

  2. Avatar von Hifni Nazeer

    Great! Would be great if you could share the entire code 🙂

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

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