Apache Unicode AuthName strings?

0

Issue

I added a username and password for a basic authentication on Apache, and I want to have Unicode AuthName strings to 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 appears to be garbage in my browser. How do I make it appear properly?

Solution

You may not be able to make it work, lack of browser support is the main issue, see What character encoding should I use for a HTTP header?.
The AuthName appears as the realm in the WWW-Authenticate header:

WWW-Authenticate: Basic realm="Some Unicode Here"

Some quick experimentation shows:

  • Apache does not encode a UTF-8 AuthName string in the config, it sends it as-is
  • Firefox, MSIE and Chrome all (correctly) interpret that UTF-8 byte sequence as ISO-8859-1 (and hence likely display it incorrectly)
  • none support RFC-2047 MIME encoding as stated by HTTP RFC-2616, the display it literally as =?utf-8?B?U29tZSBVbmljb2RlIEhlcmUK?=

(I suggest mod_auth_tkt as cookie-based a replacement for basic auth if you have the option, it has a drop-in htpasswd style perl script, and sets REMOTE_USER, you just need to roll your own form.)

Answered By – mr.spuratic

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More