Skip to content

Commit cf741dc

Browse files
committed
sample code to use Azure AD auth to pubish events
1 parent 2055278 commit cf741dc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

articles/event-grid/authenticate-with-active-directory.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Authenticate Event Grid publishing clients using Azure Active Directory
33
description: This article describes how to authenticate Azure Event Grid publishing client using Azure Active Directory.
44
ms.topic: conceptual
55
ms.custom: build-2023
6-
ms.date: 01/05/2022
6+
ms.date: 08/17/2023
77
---
88

99
# Authentication and authorization with Azure Active Directory
@@ -69,6 +69,23 @@ With RBAC privileges taken care of, you can now [build your client application t
6969

7070
Use [Event Grid's data plane SDK](https://devblogs.microsoft.com/azure-sdk/event-grid-ga/) to publish events to Event Grid. Event Grid's SDK support all authentication methods, including Azure AD authentication.
7171

72+
Here's the sample code that publishes events to Event Grid using the .NET SDK. You can get the topic endpoint on the **Overview** page for your Event Grid topic in the Azure portal. It's in the format: `https://<TOPIC-NAME>.<REGION>-1.eventgrid.azure.net/api/events`.
73+
74+
```csharp
75+
ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredential();
76+
EventGridPublisherClient client = new EventGridPublisherClient( new Uri("<TOPIC ENDPOINT>"), managedIdentityCredential);
77+
78+
79+
EventGridEvent egEvent = new EventGridEvent(
80+
"ExampleEventSubject",
81+
"Example.EventType",
82+
"1.0",
83+
"This is the event data");
84+
85+
// Send the event
86+
await client.SendEventAsync(egEvent);
87+
```
88+
7289
### Prerequisites
7390

7491
Following are the prerequisites to authenticate to Event Grid.

0 commit comments

Comments
 (0)