Integrate Azure Event Grid with Auth0
This article describes how to connect your Auth0 and Azure accounts by creating an Event Grid partner topic.
Note
See the Auth0 event type codes for a full list of the events that Auth0 supports
Send events from Auth0 to Azure Event Grid
To send Auth0 events to Azure:
- Register the Event Grid resource provider with your Azure subscription.
- Authorize partner to create a partner topic in your resource group.
- Request Auth0 to enable events flow to a partner topic by setting up an Auth0 partner topic in the Auth0 Dashboard.
- Activate partner topic so that your events start flowing to your partner topic.
- Subscribe to events.
Register the Event Grid resource provider
Unless you've used Event Grid before, you'll need to register the Event Grid resource provider. If you’ve used Event Grid before, skip to the next section.
In the Azure portal, do the following steps:
On the left menu, select Subscriptions.
Select the subscription you want to use for Event Grid from the subscription list.
On the Subscription page, select Resource providers under Settings on the left menu.
Search for Microsoft.EventGrid, and confirm that the Status is Not Registered.
Select Microsoft.EventGrid in the provider list.
Select Register on the command bar.
Refresh to make sure the status of Microsoft.EventGrid is changed to Registered.
Authorize partner to create a partner topic
You must grant your consent to the partner to create partner topics in a resource group that you designate. This authorization has an expiration time. It's effective for the time period you specify between 1 to 365 days.
Important
For a greater security stance, specify the minimum expiration time that offers the partner enough time to configure your events to flow to Event Grid and to provision your partner topic. Your partner won't be able to create resources (partner topics) in your Azure subscription after the authorization expiration time.
Note
Event Grid started enforcing authorization checks to create partner topics around June 30th, 2022.
Sign in to the Azure portal.
In the search bar at the top, enter Partner Configurations, and select Event Grid Partner Configurations under Services in the results.
On the Event Grid Partner Configurations page, select Create Event Grid partner configuration button on the page (or) select + Create on the command bar.
On the Create Partner Configuration page, do the following steps:
In the Project Details section, select the Azure subscription and the resource group where you want to allow the partner to create a partner topic.
In the Partner Authorizations section, specify a default expiration time for partner authorizations defined in this configuration.
To provide your authorization for a partner to create partner topics in the specified resource group, select + Partner Authorization link.
On the Add partner authorization to create resources page, you see a list of verified partners. A verified partner is a partner whose identity has been validated by Microsoft. Follow these steps to authorize Auth0 to create a partner topic.
Select the verified partner (Auth0, SAP, Tribal Group, or Microsoft Graph API) from the list of verified partners.
Specify authorization expiration time.
select Add.
Important
Your partner won't be able to create resources (partner topics) in your Azure subscription after the authorization expiration time.
Back on the Create Partner Configuration page, verify that the partner is added to the partner authorization list at the bottom.
Select Review + create at the bottom of the page.
On the Review page, review all settings, and then select Create to create the partner registration.
Set up an Auth0 partner topic
Part of the integration process is to set up Auth0 for use as an event source by using the Auth0 Dashboard.
- Log in to the Auth0 Dashboard.
- Navigate to Monitoring > Streams.
- Click + Create Log Stream.
- Select Azure Event Grid and enter a unique name for your new stream.
- For Subscription ID, enter your Azure subscription ID.
- For Azure Region, select the Azure region in which the resource group exists.
- For Resource Group, enter the name of the resource group.
- For Filter by Event Category, select All or filter for specific types of events.
- Select Use a specific day and time to start the stream from option if you want the streaming to start on a specific day and time.
- Click Save.
You should see the partner topic in the resource group you specified. Activate the partner topic so that your events start flowing to your partner topic. Then, subscribe to events.
Activate a partner topic
In the search bar of the Azure portal, search for and select Event Grid Partner Topics.
On the Event Grid Partner Topics page, select the partner topic in the list.
Review the activate message, and select Activate on the page or on the command bar to activate the partner topic before the expiration time mentioned on the page.
Confirm that the activation status is set to Activated and then create event subscriptions for the partner topic by selecting + Event Subscription on the command bar.
Subscribe to events
First, create an event handler that will handle events from the partner. For example, create an event hub, Service Bus queue or topic, or an Azure function. Then, create an event subscription for the partner topic using the event handler you created.
Create an event handler
To test your partner topic, you'll need an event handler. Go to your Azure subscription and spin up a service that's supported as an event handler such as an Azure Function. For an example, see Event Grid Viewer sample that you can use as an event handler via webhooks.
Subscribe to the partner topic
Subscribing to the partner topic tells Event Grid where you want your partner events to be delivered.
In the Azure portal, type Event Grid Partner Topics in the search box, and select Event Grid Partner Topics.
On the Event Grid Partner Topics page, select the partner topic in the list.
On the Event Grid Partner Topic page for the partner topic, select + Event Subscription on the command bar.
On the Create Event Subscription page, do the following steps:
Enter a name for the event subscription.
For Filter to Event Types, select types of events that your subscription will receive.
For Endpoint Type, select an Azure service (Azure Function, Storage Queues, Event Hubs, Service Bus Queue, Service Bus Topic, Hybrid Connections. etc.), or webhook.
Click the Select an endpoint link. In this example, let's use Azure Event Hubs destination or endpoint.
On the Select Event Hub page, select configurations for the endpoint, and then select Confirm Selection.
Now on the Create Event Subscription page, select Create.
Try invoking any of the Auth0 actions that trigger an event to be published to see events flow.
Verify the integration
To verify that the integration is working as expected:
- Log in to the Auth0 Dashboard.
- Navigate to Monitoring > Streams.
- Click on your Event Grid stream.
- Once on the stream, click on the Health tab. The stream should be active and as long as you don't see any errors, the stream is working.
Delivery attempts and retries
Auth0 events are delivered to Azure via a streaming mechanism. Each event is sent as it's triggered in Auth0. If Event Grid is unable to receive the event, Auth0 will retry up to three times to deliver the event. Otherwise, Auth0 will log the failure to deliver in its system.