caddyauth: Allow user-configurable headers and status code#7289
caddyauth: Allow user-configurable headers and status code#7289tie wants to merge 1 commit intocaddyserver:masterfrom
Conversation
|
Thanks, the code looks good (though it seems to be missing Caddyfile support but that may be on purpose?) but I don't understand the motivation. Why would alternate headers ever be used for basic auth? What's the real-world usecase here? What would this allow you to do exactly? |
This allows using
Yes, I don’t think it makes sense to expose this as-is in basic_auth Caddyfile syntax — it’s not really designed to extensible. I find the following confusing e.g. compared to |
|
That doesn't answer my question. In what situation would you need Caddy to solve proxy authentication like this? What is in front of or behind Caddy that would necessitate that? Why not just use the forwardproxy plugin, doesn't it already do that? Describe an actual real-world example (what other software would be used alongside Caddy for this, etc) Also yes I agree the single line Caddyfile syntax does not make sense, but the block syntax you showed is not actually implemented by your code changes. You didn't update the Caddyfile unmarshal code to add support for those options. Also should have a Caddyfile adapt test (see |
Summary
This change alllows user-configurable headers and status code for HTTP basic authentication handler.
Motivation
This change allows using
basic_authauthentication provider for web proxies (i.e. http_proxy). E.g. forwardproxy currently implements its own authentication that is identical to basic_auth, except that forward proxies use different headers (Authorization→Proxy-Authorization,WWW-Authentication→Proxy-Authenticate) and respond with HTTP status code 407 Proxy Authentication Required instead of 401 Unauthorized.See https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Authentication#proxy_authentication
Changes
authorization_headerandauthenticate_headerfields tobasic_authauthentication provider.status_codefield toauthenticationhandler (with support for expressions, similar to static response).net/http/internal/asciipackage source tointernal/ascii.parseBasicAuthwith tests based onnet/http.parseBasicAuth. The function itself was copied as is, the tests were modified to cover more edge cases.authenticationhandler withbasic_authprovider (with proxy authentication).Assistance Disclosure
No AI was used.