I recently attended a training session with the Auth0 Dev Rel team on a very cool new feature they have added called Auth0 Actions. In this article, I am going to explain what is Auth0 Actions, why to use them, and how to set one up.

What are Auth0 Actions?

Actions are secure, tenant-specific, versioned functions written in Node.js that execute at certain points during the Auth0 runtime. Actions are used to customize and extend Auth0's capabilities with custom logic.

Above, you can see a sample flow where once the user logs into the system, you add a trigger to verify the user's identity using Onfido and then confirm consent using OneTrust before completing the login flow and issuing the token.

In brief, an action is a programmatic way to add custom business logic into your login flow.

Why use Auth0 Actions? ๐Ÿค”

  1. Extensibility - Built to give developers more tooling and a better experience in their login workflows.
  2. Drag N Drop Functionality โ€” The flow editor lets you visually build custom workflows with drag and drop Action blocks for complete control.
  3. Monaco Code Editor โ€” Designed with developers in mind, you can easily write JavaScript functions with validation, intelligent code completion, and type definitions with TypeScript support.
  4. Serverless Environment โ€” Auth0 host's your custom Action functions and processes them when desired. The functions are stored and run on their infrastructure.
  5. Version Control โ€” You have the ability to store a history of individual Action changes and the power to revert back to previous versions as needed.
  6. Pre-Production Testing โ€” Your personal Actions can be drafted, reviewed, and tested before deploying into production.

How Do I Set One Up? ๐Ÿ˜ฎ

For the purpose of this demo, we are going to be creating an action to enforce Multi-Factor Authentication (MFA) for a specific role. I will take you through the process of:

  1. Creating a role
  2. Adding users
  3. Setting up a demo application
  4. Creating an Action to enforce MFA
  5. Testing the code

Let's get started:

1) Login to Your Auth0 Account

The first step to secure your application is to access the Auth0 Dashboard in order to create your Auth0 application. If you havenโ€™t created an Auth0 account, you can sign up for a free one now.

2) Create an Application

3) Setup Application

4) Setup Users and Roles

5) Setup Actions

  if (event.authorization != undefined && event.authorization.roles.includes("Admin")) {
      api.multifactor.enable("any");
  };

6) Testing With Your Application

Now when you go to login in on the locally running application, we should be triggered to do a MFA for the admin user. So let's test that.

  if (event.authorization != undefined && event.authorization.roles.includes("Admin")) {
      api.multifactor.enable("any");
  };

Conclusion

Congrats, you have just created a custom Auth0 Actions flow and tested it. This was a simple example to enable you to understand what they are, how they can be built and used in your workflows. There are many more complex flows you can build for, and you can find some examples provided by Auth0 below. Just click on the trigger, and you will find specific examples.

Sample Actions Code

Hopefully, this enables you to understand what actions are and how you can use them in your login workflows.

Thanks for reading! I really hope that you find this article useful. I invite you to participate in the discussion in the comments below; I'm always interested to know your thoughts and happy to answer any questions you might have in your mind. If you think this post was useful, please like the post to help promote this piece to others.

Thanks for reading! ๐Ÿ˜ƒ

P.S Do feel free to connect with me on LinkedIn or Twitter

Appendix

The following have been great material that helped me write this article:


Also Published Here