4.1 Create an Action - Group

1. Open the CIC management dashboard

https://manage.auth0.com/.

2. Under Actions, click on Library

Step 2 screenshot

3. Click on Build Custom

Step 3 screenshot

4. Name it as “Authfest VIPs”

Step 4 screenshot

Click on Create to set up the Action.

6. Paste this code into your action

// Adds a custom claim "group" with the value "VIP" if the user's email ends in "@authfest.com".
//
// @param {Event} event - Details about the user and the context in which they are logging in.
// @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.  

exports.onExecutePostLogin = async (event, api) => {
  // Check if the user's email ends with "@authfest.com".
  if (event.user.email.endsWith('@authfest.com')) {
    // Add the custom claim "status" with the value "VIP" to the access Token.
    api.accessToken.setCustomClaim('group','VIP');
  }
  else{
    // Add the custom claim "status" with the value "REGULAR" to the access Token.
    api.accessToken.setCustomClaim('group','GENERAL');
  }
};

7. Click on Deploy

Step 7 screenshot

8. Click on Flows

Step 8 screenshot

9. Click on the Login Flow

We are now going to include the action in the login flow. Step 9 screenshot

10. Click on Custom

Step 10 screenshot

11. Drag and drop your action

Step 11 screenshot

12. Click on Apply

Your flow is going to be updated Step 12 screenshot

13. Done!

Every time a user logs in now, it will run our action. If the user logs in with an email that ends with “@authfest.com”, their access token will receive a new “VIP” claim.

P.S.: Worried about the latency such an action causes? Don’t be - simple actions like that mostly run in far less than 50 ms, and are always available and ready to go. Check your tenants logs after your next login to see the impact!