In basic authentication, the realm parameter is not sent back to the server. Thus, the server cannot check whether the client sends an authorization header for the same area or not. It depends on the customer. The correct implementation of basic HTTP authentication. So:
Now the problem is that as soon as I enter one of the applications, say private / foo, Chrome does not ask me for the username and password for other applications (private / moo, etc.). This is contrary to intuition, since all instances are uniquely identified by their URLs.
As Andrew noted, and clearly from the RFC, the URL does not play a role here. But if '/ foo' is protected, '/ foo / moo' is protected in the same area.
Using different credentials for each instance does work, but shouldn't request Chrome credentials at least once for each instance?
On the sidelines, what happens (when checking with the debugger tools) is that after I registered once in one of the applications, say private / foo, Chrome re-sends the same authorization header to others applications, say moo, without prior request.
The RFC says that the client can send the appropriate authorization header for the area without first requesting the server.
It seems that Chrome applies to all my applications located in the same area or forwarding the same authorization header in different areas. I do not think this is the expected behavior, but I could have missed something. Firefox behaves the same. In any case, this was not the essence of the matter.
Question topic: "How do I get Chrome to ask me for a username and password at least once for each instance? Basic auth does not work as I expected, why?"
Use digest authentication (RFC 2617 again). Rack implements a version of the MD5 algorithm in Rack::Auth::Digest::MD5 . Set different opaque for each instance, and you are good to go:
# ... realm = "Description of the protected area." opaque = "Secret key that uniquely identifies a realm." users = {'user' => 'password'} use Rack::Auth::Digest::MD5, realm, opaque do |username| users[username] end
opaque sent back by the client and can be verified on the server side that the authorization request is for the correct resource. The work of realm seems to be a descriptor in nature - what area or resource are you trying to protect? what id will i blink?
RFC: http://tools.ietf.org/html/rfc2617