RoundCube webmail is a browser-based multilingual IMAP client with an application-like user interface. It provides full functionality you expect from an email client, including MIME support, address book, folder manipulation, message searching and spell checking.
Add a new virtual host webmail.domain.tld
Add a new rule:
"^/\?_task\=logout" -> "logout_app https://auth.domain.tld"
in HTTP headers, you need Auth-User ($mail) and Auth-Pw ($_password).
To be able to forward password to RoundCube, see how to store password in session
Configure Apache or Nginx virtual host
install http_authentication plugin
Patch it to replace
enable http_authentication plugin in main.inc.php :
$rcmail_config['plugins'] = array('http_authentication');