Feign: Digest auth

Created on 10 Jan 2017  Â·  5Comments  Â·  Source: OpenFeign/feign

Can feign support digest auth?

waiting for votes

Most helpful comment

If I need to implement Digest certification, first of all, I'll write a RequestInterceptor. But the Digest auth needs to be ‘401‘ to get the 'nonce' data, I can write a ErrorDecoder.Default like: "if (response.status) (response.headers) (= = 401 & &.ContainsKey (" www-authenticate "))," how to re launch the request?

All 5 comments

Not by default. You'd need to write a RequestInterceptor similar to BasicAuthRequestInterceptor.

If you want to tackle it, pull requests are welcome.

If I need to implement Digest certification, first of all, I'll write a RequestInterceptor. But the Digest auth needs to be ‘401‘ to get the 'nonce' data, I can write a ErrorDecoder.Default like: "if (response.status) (response.headers) (= = 401 & &.ContainsKey (" www-authenticate "))," how to re launch the request?

I had the same problem and was surprised I could find no solution anywhere. HTTP Digest was the only authentication method supported by the server I was trying to connect to so I had no choice but to roll up my sleeves and do it.

In the end, I had to create a class that implements RequestInterceptor, Retryer and ErrorDecoder.

This is because we need to make sure we always retry when getting a first 401 and store the information sent via the WWW-Authenticate header.

You can find my implementation in Kotlin here: https://gist.github.com/cesartl/3dd0541d0b71771daac28bad9a08512d

It tried to implement the spec as close as possible but I can't guarantee it will work for everyone. I only tested it with one server.

Still, it should give you a good starting point.

I'm going to close this issue and recommend that questions like this be made on Stack Overflow, allowing more users to help you.

Was this page helpful?
0 / 5 - 0 ratings