Given that the legacy package is deprecated and not recommended, this is based on use of the current generation management package, Azure.ResourceManager.EventHubs
.
There is no need to work with Microsoft.Identity.Client
or any of the related types; the auth story for the current generation has been simplified to work directly with Azure.Identity
token types that manage token acquisition implicitly.
There's a full sample here, but the important parts are:
// Create your client
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Get the subscription
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
// Get the resource group
ResourceGroupResource resourceGroup = await subscription.GetResourceGroupAsync("myRg");
// Get your Event Hubs namespace
EventHubsNamespaceCollection namespaceCollection = resourceGroup.GetEventHubsNamespaces();
EventHubsNamespaceResource eventHubNamespace = await namespaceCollection.GetAsync("myNamespace");
// Create your Event Hub
EventHubResource eventHub =
(await eventHubCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"myEventhub",
new EventHubData())
).Value;
More information on using Azure.Identity
to authenticate can be found in the Overview docs.