Git Product home page Git Product logo

csharp-dotnet-digest-authentication's Introduction

Digest Authentication in .NET - An Example

UPDATE (03/10/2022): .NET 6 should now successfully do digest authentication, as kindly pointed by someone in the example repository. Should save you the hassle of doing it manually, like in this repository!

This project contains an extension method in HttpClientExtensions that should work out of the box for basic digest authentication, and be a good starting point to expand upon.

I couldn't personally find a way within .NET to handle digest authentication, and the ways that were documented flat out didn't work.

I might release this as a Nuget package if I get the time.

Example Usage

The integration test in HttpClientExtensionTests provides the best example usage of the simple extension method:

var client = new HttpClient();
client.BaseAddress = new Uri("https://httpbin.org");
var request = new HttpRequestMessage(HttpMethod.Get, "/digest-auth/auth/username/password");
request.Headers.Add("Accept", "*/*");
request.Headers.Add("User-Agent", "HttpClientDigestAuthTester");
request.Headers.Add("Accept-Encoding", "gzip, deflate, br");
request.Headers.Add("Connection", "keep-alive");

var response = await client.SendWithDigestAuthAsync(request, HttpCompletionOption.ResponseContentRead, "username", "password");

Compatibility

The HttpClientDigestAuth targets .NET Core 3.1, as this is most supported, being a LTS release, and stable .NET version before the newly released .NET 6.0.

csharp-dotnet-digest-authentication's People

Contributors

callumhoughton18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

csharp-dotnet-digest-authentication's Issues

Integrated .NET solution

Hey,

on your blog you asked for information if someone finds a default way to do this.

I got the digest authentication working for an IoT device on .NET 6 just with this little code:

using System.Net;

var handler = new HttpClientHandler(){
 Credentials = new NetworkCredential("user", "pw")
};
var httpClient = new HttpClient(handler);

var response = await httpClient.GetAsync("http://my.url");
response.EnsureSuccessStatusCode();

Seems the framework does automatically detect the authentication method from the initial 401 response and then performs the hashing stuff and so on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.