You could use the flow that the OAuth module uses for inspiration. And instead of showing a Mendix page still show the login page with the regular form. Use a request handler to catch that form post and then from that point forward you can use microflows called from the java request handler.
In the Oauth module you are redirected to your Oauth provider for authentication, and the callback comes back to another request handler that handles the result. Of course you could directly go to the callback and process the login request.