I think the reason it's not working is because of the realm that you set in your basicauthhandler is not the same as the one you set in your .htaccess file.

So we could ask the user for the proper realm, or we could indeed use your snippet which works well and that would mean less configuration for the user. I'm fine with that as it appears to be working quite well.