question

StephanWedig-1146 avatar image
0 Votes"
StephanWedig-1146 asked bharathn-msft edited

Create EventHub from a web app

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

stan avatar image
0 Votes"
stan answered stan commented

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

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you have an idea which permission I need?

0 Votes 0 ·
stan avatar image stan StephanWedig-1146 ·

If you just need to read the resources reader should be fine. Permissions will depend on what your application needs to do and to which resources exactly. There are built-in roles you can use and there is a way to create custom roles. When you have the roles that you need you can create role assignments to give the actual permissions What is Azure role-based access control (Azure RBAC)?


0 Votes 0 ·

I think I didn't understand whart I do. In the first step I want to read the eventhub from a namespace. Later I want to create eventhubs.

I have a web app in Azure. I have created in the AAD an app registration for this web app. On this point the user have to login for using my app. Did I add the permission in the app registration or on another place? Under permission I don't find an option to add the permission to access the eventhub management.

0 Votes 0 ·
Show more comments