Apache 2.3/2.4 has mod_auth_form that allows to display a HTML form for users to login. Can I, instead of using a plain HTML form use an application server to provide the form (J2EE, node.js, PHP, Vert.x etc) and the authentication logic and just return the session cookie (how would that need to look like?)
Yes. But you need to use input fields with name = httpd_username and httpd_password (and .htaccess rights as well)
/secret/path/.htaccess
/logout/.htaccess
p.s.: don't use "secret" word from Apache Docs as a passphrase ;)