reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Digest authentication?

Open ZanderBrown opened this issue 5 years ago • 5 comments

'basic' is already implemented, would be useful to have 'digest' as well

ZanderBrown avatar Mar 28 '19 22:03 ZanderBrown

This would be difficult for reqwest to do, since it involves making two requests to the server. You need to do a HEAD request to get a "nonce" and "opaque" value from the server, use the nonce in the digest, and pass the "opaque" value back with the real request as well. I doubt as a library that reqwest should make "extra" requests for you. Also, you need to depend on md5 most likely (as that's the default digest algorithm).

IslandUsurper avatar Apr 21 '20 12:04 IslandUsurper

I found this crate https://crates.io/crates/digest-headers, but it's not supported long time. Maybe it will be useful for implementing this feature or for workaround. So It would be great if it were implemented for reqwest.

0xmad avatar May 02 '20 21:05 0xmad

Any updates on this?

valmirjunior0088 avatar May 29 '20 16:05 valmirjunior0088

I third the request for this, but for others, the way I'm implementing it now is using:

https://docs.rs/digest_auth/0.2.3/digest_auth/

Code snippet:

use digest_auth::AuthContext;
...
    // Step 1:  Get the auth header
   // client in this case is a reqwest::blocking client;  add .awaits as needed
    let res = client.get(url).send()?;
    let headers = res.headers();
    let wwwauth = headers["www-authenticate"].to_str()?;

    // Step 2:  Given the auth header, sign the digest for the real req.
    let parsed_uri = url.parse::<http::Uri>()?;
    let context = AuthContext::new(USERNAME_GOES_HERE, PASSWORD_GOES_HERE, parsed_uri.path());
    let mut prompt = digest_auth::parse(wwwauth)?;
    let answer = prompt.respond(&context)?.to_header_string();
    client.get(url).header("Authorization", answer).send()?

I'm probably holding it wrong in several places but this works.

dave-andersen avatar Aug 15 '20 15:08 dave-andersen

I wrote diqwest for that: https://github.com/maoertel/diqwest.

It abstracts everything away and you can use it with async and blocking reqwest.

maoertel avatar May 28 '22 17:05 maoertel