Need to call login java action manually on user login

I need to take user login inputs : username and password and call my REST service which logs in with those user inputs to my external application server which has all my APIs(GET, POST etc.) hosted. The login REST API returns a service-ticket which I use to call all other APIs.   Now I need to somehow call this login service when user hits sign-in button –> Call my login REST API –> If ticket is returned then – > Login in Mendix otherwise, throw error that “Login is unsuccessful. Please try again” and show the login page again. I searched everywhere to achieve this.  Already tried sign-in microflow, but that is deprecated. How can I achieve this? Mendix modeller version : 7.20.1
1 answers

I believe the easiest way to do this is to overwrite the login action. You can find example code in the Mendix Login Guard AppStore module (the documentation also contains a link to a blog post explaining this).


Once you are in the Java action, you can call a microflow with the Core.execute() method. In this microflow, you call your API with the username and password the user has provided and store the token. You can then continue logging in the user from the Java action.


Finally, if all your application does is call APIs, you could also model your app for anonymous users. If the user wants to call an API, you ask for a username and password. You store the token in a non persistent entity attached to System.Session. For each subsequent call, you retrieve the token, and use that as input for the API call. You may not need to log in your users, if all information comes from an external system. Be careful with persistent entities in such a scenario and double check your security (e.g. with the SecurityInspector widget).