Forum Moderators: phranque
Details:
When the user should authenticate, the HTTP response contains three WWW-Authenticate headers:
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="abcd.efg"
What I want to do is to remove the first two, so that the client only sees Basic Authentication. How can I do that?
A simple solution that I came up with was to use the headers module and ALWAYS set the WWW-Authenticate response header to Basic Authentication (removes all the original WWW-Authenticate headers). However, that solution is not perfect as the authentication header shouldn't be there when the user is already authenticated. Always setting the header makes the authentication dialog pop-up every now and then.
Is there a better way? Worst case scenario would be to write my own module, but maybe there's an easier way?
Thanks!
Welcome to WebmasterWorld!
Have you tried using the
Header onsuccess unset WWW-Authenticate
Header unset WWW-Authenticate
Header set WWW-Authenticate Basic realm="abcd.efg"
Header onsuccess unset WWW-Authenticate
I haven't used this myself, and the above is based completely on the Apache 2.0 mod_headers documentation. In other words it's a guess, but it's what I would try if I was working on this project. :)
Jim
I tried it with the "onsuccess" flag, but the funny thing is that the header is then (it seems) removed for every response, even the ones with 401 status. I also tried "always", but then it is never removed (not even for 2xx statuses).
The strange thing is that in the change log for Apache 2.0.51 it states:
*) Backport from 2.1 / Regression from 1.3: mod_headers now knows
again the functionality of the ErrorHeader directive. But instead
using this misnomer additional flags to the Header directive were
introduced ("always" and "onsuccess", defaulting to the latter).
PR 28657. [AndrÚ Malo]
"onsuccess" seems to be the default behavior. That's probably why I seem to get the same behavior as when not stating any condition (the header is removed/unset). However, I cannot get the behavior to match the documentation:
The optional condition can be either onsuccess or always. It determines, which internal header table should be operated on. onsuccess stands for 2xx status codes and always for all status codes (including 2xx). Especially if you want to unset headers set by certain modules, you should try out, which table is affected.