Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.
The CLI command uses DefaultAzureCredential
which is based of az login command to fetch the Event Hub namespaces. Your program on the other end is using ClientSecretCredential
. I have tested the same code and could fetch the Event Hub namespaces without any issues.
Since you are using local variables in your code, I recommend removing the OR
conditionality check when assigning the subscriptionId in line 31 of the code. It could be possible that there might be a different Subscription ID being pulled from environment variables. Since we have an logical ||
conditionality check, it will take precedence over the subscription you are trying to set after the operator. In this case, if process.env["EVENTHUB_SUBSCRIPTION_ID"]
has a value, that is the subscription being queried upon.
To test my code, I have used the Client ID and Tenant ID from my application registration overview page which can be access from Microsoft Entra Admin Center. Please find the below image for reference.
I have passed the application Client Secret value to the parameter client secret. Please find the below image for reference.
In addition to setting these values, please ensure your application has access to Azure Event Hub resource. You can follow the steps in the section Assign a role to the application to grant access.
Once you have verified and assigned appropriate values, your code should work as expected and fetch the Event Hub namespaces.
Hope this helps! Please let us know if you need any additional assistance or need further clarification.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.