Create EventHub from a web app

Stephan Wedig 1 Reputation point
2021-07-07T07:27:26.68+00:00

Hi,

actually I begin to develop some programms for Azure. I want to select from a specific event hub namespace the existing event hubs. I wrote the code below but I get the following error message when the program try execute line 9:

ErrorResponseException: Operation returned an invalid status code 'Forbidden'
Microsoft.Azure.Management.EventHub.EventHubsOperations.ListByNamespaceWithHttpMessagesAsync(string resourceGroupName, string namespaceName, Nullable<int> skip, Nullable<int> top, Dictionary<string, List<string>> customHeaders, CancellationToken cancellationToken)

var cred = new ClientCredential(clientId, secretName);
var context = new AuthenticationContext($"https://login.microsoftonline.com/{tenantId}/");

var token = await context.AcquireTokenAsync(
                @"https://management.core.windows.net/",
                cred
);
var serviceClientCredentials = new TokenCredentials(token.AccessToken);
var eventHubManagementClient = new EventHubManagementClient(serviceClientCredentials) {
       SubscriptionId = subscriptionID
};
var eventhubs = eventHubManagementClient.EventHubs.ListByNamespace(resGroup, eventHubNamespace);
foreach (var eventhub in eventhubs)
       Models.Add(new PizzaCreator { Name = eventhub.Name });

Has someone an idea where the problem could be?

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
567 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Stanislav Zhelyazkov 21,506 Reputation points MVP
    2021-07-07T07:55:35.167+00:00

    Most likely the credentials you are using does not have permissions.