AphName strings for Unicode?
I added a username and password for basic authentication in Apache and I want my unicode AuthName strings to be my users. My httpd.conf looks like this:
<Location "/">
AuthType Basic
AuthName "Some Unicode Here"
AuthUserFile /somewhere/htpasswd
Require valid-user
</Location>
But " Some Unicode Here
" always seems to be garbage in my browser. How can I make it right?
You might not be able to get it to work, the browser support issue is the main issue, see What character encoding should I use for the HTTP header? ...
AuthName
displayed as an area in the header WWW-Authenticate
:
WWW-Authenticate: Basic realm="Some Unicode Here"
Some quick experiments show:
- Apache does not encode UTF-8 string
AuthName
in config, it sends it as-is - Firefox, MSIE and Chrome all (correctly) interpret the UTF-8 byte sequence as ISO-8859-1 (and therefore probably display it incorrectly)
- no RFC-2047 MIME encoding support as specified in HTTP RFC-2616, display literally
=?utf-8?B?U29tZSBVbmljb2RlIEhlcmUK?=
(I suggest mod_auth_tkt
as a cookie to replace basic auth if you have the option it has a drop-in htpasswd style perl script and it sets REMOTE_USER
, you just have to roll your own form.)
I found the correct solution for .htaccess AuthName containing accented characters:
Save the file in the correct encoding using a text editor or "iconv".
In Sublime 3, I used File → Save with Encoding → Western ISO-8859-1