DEV Community

Robertino
Robertino

Posted on

Managing Trial Periods with Auth0 Actions

How to use Auth0 Actions to let users access your application or website for a trial period.


Assume you want to let users try your application's services for a given period of time, say 30 days. How can you let users register and then block them after the trial period expires? You can easily leverage Auth0 Actions to achieve this result.

Setting Up the Sample App

To show you how to enable a trial period for your application, this article will be referring to a sample web application that allows the user to access a fictitious online catalog.

The sample application you are going to use in this article is built with C# and requires .NET installed on your machine. However, the user registration customization you will implement is independent of your application's specific programming language and framework.

You can download the sample application by cloning its GitHub repository with the following command:

git clone https://github.com/auth0-blog/acme-aspnet-mvc.git
Enter fullscreen mode Exit fullscreen mode

Once you download it, take a look at the README file and follow its instructions to configure the application to use Auth0. You need an Auth0 account, and if you don't yet have it, you can sign up for a free one.

If you want to learn the details of the sample application implementation, this blog post describes how it has been integrated with the Auth0 authentication services.

After configuring the sample application, you can run it with the following command:

dotnet run
Enter fullscreen mode Exit fullscreen mode

Now, head your browser to the https://localhost:7095/ address, you should get the following page:

Sample app home page

Auth0 Actions and Flows

Once you have ensured that your application is properly configured and running, let's briefly explore Auth0's features that will allow you to implement the trial period: Auth0 Actions and Flows.

Auth0 Actions are JavaScript functions running in a Node.js environment executed when specific events happen in a few internal Auth0 Flows.

Auth0 Flows are the processes that can be extended with Actions. Each Flow is made up of one or more triggers and represents the logical pipeline through which information moves during a single point in the Auth0 journey.

For example, you can consider the Login Flow, which runs when a user logs in. This Flow has a post-login trigger: an event fired after the user logs in. You can handle this event through one or more Actions. In other words, you can see Actions as event handlers that run when a specific event fires in an Auth0 Flow.

The following is a graphical representation of an Action (AddRoles) that will be executed in the Login Flow after the user logs in:

Auth0 Action in the Login Flow

The following are the available Auth0 Flows you can customize with Actions:

  • Login, running when a user logs in.
  • Pre User Registration, running before a user is added to the users' store.
  • Post User Registration, running after a user is added to the users' store.
  • Post Change Password, running after the user changes their password.
  • Send Phone Message, running when you configure a custom Multi-Factor Authentication (MFA) provider.
  • Machine To Machine, running when an access token is issued to a client using the Client Credential Flow.

You will use a couple of these Flows to implement the trial period feature for the sample application.

To learn more about Actions, you can check out these blog posts for a quick introduction to Auth0 Actions and how they compare with the deprecated Rules and Hooks.

Read more...

Top comments (0)