Dynamic Role-Based Authorization with External API in Mendix

0
Question: I'd appreciate clarification on integrating user roles and authorizations from an external service into my Mendix project. Can I import user roles and their corresponding permissions (such as page, entity, and microflow authorizations) directly from an external API into my Mendix application? In particular, I'm interested in knowing if I can dynamically assign roles and permissions based on API information, ensuring that users with specific roles have access to certain pages and features, while others do not. Please let me know if this is feasible and if so, what steps I need to take to achieve this integration. Thank you for your time and assistance. Sincerely, Omer
asked
2 answers
1

As Jelle already mentioned, you cannot create or define userroles using an API. What you can do however, is create a mapping between roles returned by an API and the userroles in Mendix. 

 

For example, you have defined in Mendix the following userroles: "Manager", "Administrator" and "User".

The API returns would then return the role for a specific user e.g. "SalesManager", "SalesEmployee", etc. 

In your app, you will need a separate entity e.g. "APIRole", one object for each API user role, associated to the System.UserRole object (e.g. "SalesManager" maps to "Manager", "SalesEmployee" to "User", etc)

 

You can then process the API response to retrieve the API role object, retrieve the associated System.UserRole object over association and connect that to the user.

 

This method of assigning user roles is also implemented within the OIDC module (combined with the UserCommons module) in the marketplace.

answered
1

Hello Omer,

 

Simple answer is:

No, it is not possible to import userroles and their corresponding permissions directly from an external API into Mendix. 

 

Because userroles are created during the development of the application and are a combination of different module roles which are also created during the development of the application or created by the developer of the module.

 

https://docs.mendix.com/refguide/user-roles/ 

 

However, by designing your userroles smartly you could achieve some variation, but this is really minimalistic.

 

And I also think it is not feasible to try to get around the normal way of using the userroles

answered