Guide to Auth0 setup for Security implementation with Atoti+
Add user roles to the ID token with custom action
I have always presented different use cases for the atoti Community Edition. After experiencing and being satisfied with the Python BI analytics platform, some users ask for authentication and access management. This can easily be accomplished with the use of Atoti+ plugin.
This article is part of a series that explains how we can implement secured and managed access with Atoti+. It is mainly intended for projects that have decided on using Auth0 as their authentication providers.
Check out the corresponding YouTube video.
Type of authentication mechanisms
Talking about authentication and access management, it revolves around users. Given that big corporations usually have their existing user management solutions, it makes sense to integrate with their existing authentication provider.
Before diving into Auth0 setup, let’s take a look at the types of authentication mechanism that Atoti+ supports:
Users need to be aware that while the above is used for authentication, not all of them support user management, i.e. user profile information and roles.
For instance, with basic authentication, we define username, passwords and their roles in atoti. Kerberos handles the authentication of users but not the user roles. Likewise, connecting Google Cloud credentials via OIDC, we are only able to authenticate users but not download their associated roles to atoti. Therefore, we will assign users their roles in atoti.
We can use LDAP and OIDC for both user management and authentication (with the exception of Google Cloud credentials via OIDC). We download the roles assigned to users from these authentication providers upon login and map them to the roles defined in atoti in order to achieve access management.
If you haven’t had an authentication provider already and would like to try out the security implementation with Atoti+, give Auth0 a try.
Auth0 offers a free plan that allows up to 7000 users and you can always upgrade to a different plan as required for your project.
If you’re an existing user of Auth0, you may want to skip to the section on “Create custom action to add roles to ID token ”.
Let’s start by first creating an application for atoti in Auth0. Navigate to the Applications page and click on the “+ Create Application button”.
Select the application type “Regular Web Applications” for our Atoti+ project.
Upon creation of the application, we now have the basic information required to configure our OIDC connection in atoti.
We will dive into the atoti OIDC configuration in the next article.
Update Application URIs
We need a fixed URL to configure the application URIs in our Auth0 setup. Thus, we should configure our atoti session with a fixed port. Otherwise, a random port will be assigned for the web application.
With this in mind, fix the port in atoti during instantiation of the session as follows:
session = tt.Session(port=10011)
The below atoti code snippet will return the atoti web application URL:
With the web application URL, let’s navigate to the Application URIs section which is on the same Settings tab of the application page in Auth0.
Update the Allowed Callback URL, Allowed Logout URLs and Allowed Web Origins with the web application URL. Remember to include the following callback URL with the provider id set to auth0:
Create custom action to add roles to ID token
For atoti to apply the correct access control, we need to create a custom action that will add user roles to the ID token returned in the user’s profile.
To do so, navigate to the Library page under the Actions menu and click on the “Build Custom” button. Let’s name the action according to its purpose. The trigger for this action is the Login/Post Login action.
In my use case, I’ve used the domain assigned to my Auth0 application for the namespace.
Deploy the action so that we can apply it in our login flow.
Apply custom action to the Login flow
The below GIF shows how we can add our custom action to the login flow.
Toggle to the Flows page from the Actions menu and access the Login flow. It is a simple two-step process:
- Start — the user is authenticated and logged in
- Complete — the token is issued
We will add the roles to the token by intercepting the flow before the token is issued. To do so, simply drag and drop the custom action in between the two steps and apply.
Depending on your organization structures, create the necessary roles to group the users based on their job functions. I will spare you the process of user creation as it’s rather intuitive.
However, do know that role names in Auth0 can be different from the roles in atoti as it is a one-to-many map against the atoti roles. For instance, we can have the Auth0 role “atoti user” which maps to “ROLE_USER” in atoti.
In the event that all the users are allowed to share their dashboards, we will map the role “atoti user” to both “ROLE_USER” and “ROLE_SHARE” in atoti:
Do note that each user requires the atoti role “ROLE_USER” to be able to access the web application.
Create Users — Login with email or username
By default, Auth0 captures the user’s email address for the login. However, we can also use a username for the login. To do so, navigate to the database connection used by the application under the Authentication menu.
Toggle the switch for the “Requires Username” and also remember to set the maximum permissible length for the username.
We will now be able to capture the Username when creating a user.
So, simply fill out the form to create the user. Just remember to assign the roles to the user.
In the database connection used by the application, there is a function to try the connection.
Test the connection by logging in with one of the created users.
Success! Take a look at what the application will receive in the user profile. It will be useful for our OIDC configuration in atoti as I will show you in the next article. Stay tuned!