Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes steps to subscribe to events published by Microsoft Entra ID using the Azure portal.
Create a partner topic
Navigate to Azure portal.
In the search box, type Event Grid, and select Event Grid from the results.
On the left menu, expand Partner events, select Available partners.
On the Microsoft Entra ID tile, select Create.
On the Microsoft Graph API subscription tab of the wizard, follow these steps:
For Subscription, select the Azure subscription in which you want to create the partner topic.
For Resource group, select the resource group for the partner topic resource.
For Location, select the region in which you want to create the partner topic.
For Partner topic name, enter a name for the partner topic.
For Resource, specify the resource for which you want to receive the notifications. For example:
users
.For Change type, select the types of events for which you want to be notified.
For Expiration time, select date and time when the partner topic expires.
Select Enable lifecycle events options if you want the
Microsoft.Graph.ReauthorizationRequired
event to be supported. For details about lifecycle events, see Lifecycle notifications for subscriptions.Select Next: Partner Configuration at the bottom of the page.
On the Partner Configuration page, follow these steps:
Select + Partner Authorization.
On the Add partner authorization to create resources page, select Microsoft Graph API, specify Authorization expiration time, and select Add.
Now, on the Partner Configuration page, select Next: Review + create at the bottom of the page.
On the Review + create page, review all the settings, and select Create.
After the Graph API subscription is created and the partner topic is activated, you see a link to navigate to the partner topic in the portal.
Subscribe to partner events
At this point, Microsoft Graph API events should be arriving on your activated partner topic whenever there are changes to the resources specified when your created the Microsoft Graph API subscription. In order to process the events, you must create an event subscription that forwards the events to an event handler like a webhook or any of the supported Azure services.
Important
In this section, you find a way to receive events using a sample application, the Event Grid Viewer. This application helps you test the data pipeline to receive events before you create your own application to handle the events according to your business requirements. When you're ready to build your application, see the complete application samples.
Deploy the Event viewer application
To test your partner topic, deploy the Event Viewer, which is a prebuilt web app. The Event Viewer app displays all events delivered to it. The deployed solution includes an App Service plan, an App Service web app, and source code from GitHub.
Select Deploy to Azure to deploy the solution to your Azure subscription. In the Azure portal, provide values for the parameters.
On the Custom deployment page, do the following steps:
Select a Resource group where the application is deployed.
For Site Name, enter a name for the web app.
For Hosting plan name, enter a name for the App Service plan to use for hosting the web app.
Select Review + create.
On the Review + create page, select Create.
The deployment takes a few minutes to complete. Select Alerts (bell icon) in the portal, and then select Go to resource group.
On the Resource group page, in the list of resources, select the web app that you created. You also see the App Service plan and any other resource you have in the resource group.
On the App Service page for your web app, select the URL to navigate to the web site. The URL should be in this format:
https://<your-site-name>.azurewebsites.net
.Confirm that you see the site but no events are posted to it yet.
Create an event subscription
You subscribe to an Event Grid partner topic to tell Event Grid which events you want to track, and where to send the events.
Now, on the Event Grid Partner Topic Overview page, select + Event Subscription on the toolbar.
On the Create Event Subscription page, follow these steps:
Enter a name for the event subscription.
Select Web Hook for the Endpoint type.
Choose Select an endpoint.
For the web hook endpoint, provide the URL of your web app and add
api/updates
to the home page URL. Select Confirm Selection.Back on the Create Event Subscription page, select Create.
View your web app again, and you should see a new subscription validation event. Select the eye icon to expand the event data. Event Grid sends the validation event so the endpoint can verify that it wants to receive event data. The web app includes code to validate the subscription.
Test the event flow
You're now ready to test your Microsoft Entra ID subscription. According to the change type provided when you created the Microsoft Entra ID subscription, update, or delete the resource that you're tracking. You should see an event displayed on the Event Viewer application for every resource change you make.
Next steps
- Build your own partner event handler application
- Use the sample applications as a way to expedite your development effort. After you have your application, you can update the event subscription endpoint with your application's endpoint.
- For production purposes, you might want to automate the creation of the Microsoft Graph API subscription and hence the partner topic. To that end, the sample applications are also a good resource. You might want to consult the code snippets in section How to create a Microsoft Graph API subscription for quick reference.
- The sample applications also show you how to renew Microsoft Graph API subscriptions to ensure a continuous flow of events. You should understand the concepts behind subscription renewal and the APIs called in section How to renew a Microsoft Graph API subscription