Finally found the solution. The X-Forwarded-Proto
header must be set, which is used for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer.
Since I use HAProxy as my proxy server, I had to add this line to my HAProxy configuration:
http-request set-header X-Forwarded-Proto https if { ssl_fc }
Now login works fine even when “force https” is enabled.