Star us on Github
Blog
How to Build Your Auth0 Integration

How to Build Your Auth0 Integration

Tolga Ozen

April 21, 2022

In this article, I will explain how to build an Auth0 integration. I will perform this integration through the actions that auth0 has just introduced and are currently in beta.

What Is Action?

Auth0 actions is a feature that allows you to customize auth0 behavior. With Actions, you can add basic custom logic to your login and identity flows tailored to your needs. Actions also allow you to connect external integrations that enhance your overall extensibility experience. It allows Auth0 customers to implement solutions like authentication or permissions management without writing any code.

For example, you can add an action to your app registration flow using a Marketplace Partner that specializes in authorization.

Actions Integrations are standalone functions executed at selected points on the Auth0 platform. Written in JavaScript, they are closed source; customers cannot change the code.

Sample Application for Integration

To show you how to write an integration with a simple example, I chose to make an application that will send you an email when the user signs up.

We will use auth0 actions and amazon ses as email service to trigger this process. But you can use this flow for your own app integration.

Prerequisites

  1. Auth0 account.
  2. AWS account

Step 1: Create an Action

Log in your Auth0 account,

  • Open Actions/Library from sidebar menu.
  • Click Build Custom button on right corner.
  • Select Post User Registration.
  • Create action called ses.

Step 2: Add a Dependency

This is the field where we specify which npm packages the integration will depends on. We will use the node-ses package for our integration.

Select the action we created on the previous step. On dependency tab(the last icon) of the console,

  • Click the button Add Dependency
  • Enter name as node-ses
  • Enter latest version of our node.js package(Latest version is 3.0.3**)

Step 3: Add Secrets

Secrets allow you to safely define secret values ​​as properties of the event.secrets object. We will be able to securely access the secrets we will define from within the code we will build.

Go to the Secrets tab (above the dependency icon). We will define aws key and secret. You can generate these keys on AWS IAM dashboard.

Since it is not the subject of this article, I will use the keys I created before.

Define AWS SES Key

  • Click the button Add Secret
  • Enter key as AWS_SES_KEY
  • Enter your AWS key to the value field.

Define AWS Secret

  • Click the button Add Secret
  • Enter key as AWS_SES_SECRET
  • Enter your AWS secret to value field.

Step 4: Build your Custom Logic

In our case, it contains the onExecutePostUserRegistration function. Inside this function, we will write the code to run after the user registers a new account.


First of all, we call our package that we added as dependency here.

then let's call the secrets we created with event.secrets and set them into the initial function of the client we use.

We should call the mail sending function in the node-ses library and write the information about which email (we need to verify on aws ses) will be sent to which email when the user is registered.

You can fill in here with your own information.

if you're not ready to finalize everything in your Action, you can save it as a draft to work on later. Lastly, there's Deploy, which you use when you've tested your Action and it's ready for prime time!

Test your Actions Integration

You'll see a "play button" icon for testing your Action before deploying it on the left.

After clicking, you will see the object created by Auth0 for testing and the run button under it. Your code will run when you press the Run button.

Result

Now that we’re satisfied that the Action is working as expected, it’s time to deploy it. Select Deploy. Deploying an Action takes a snapshot of the Action at that time and records it as an Action Version.

Submit your Actions Integration

Submit your Actions Integration to Auth0 for evaluation once you've created and properly tested it: Submit a service request on the Auth0 Marketplace.

You can fill in the required fields and send a request via this link.

https://autheco.atlassian.net/servicedesk/customer/portal/1/group/1/create/43

After an initial review of the request, Auth0 sends you a link to a GitHub repository with instructions on how to document, test, and submit your Actions Integration.

Publish your Actions Integration

Auth0 will send you a preview of your action after reviewing your Actions Integration and you can confirm when to post it on the Auth0 Marketplace.

If you have any questions or doubts, feel free to ask them. For more content like this, join our newsletter.