I cannot get WithAadUserPromptAuthentication() to work when deployed in Azure Web Apps

Angelos Petropoulos 25 Reputation points Microsoft Employee
2023-10-05T07:40:05.97+00:00

My .NET web app works great locally. I am using WithAadUserPromptAuthentication() to log in as the current AAD user to make sure I don't expose through the app any data the user is not supposed to have access to.

My problem is that the application doesn't work when deployed to Azure Web Apps. According to the error message, it appears that WithAadUserPromptAuthentication() eventually tries to setup a callback on a random local port and Azure environments are locked down to just ports 80 and 8080.

User's image

Even if I could open & route a port, it appears that the actual port number changes every time.

How can I get this to work?

Thank you in advance,
Angelos

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,807 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde | MVP 32,726 Reputation points MVP
    2023-10-05T10:38:51.9+00:00

    Hello @Angelos Petropoulos

    if you want to connect to Azure Data Explorer using a Managed Identity in a web app, please try:

    var cred = new DefaultAzureCredential();
    var kcsbingest = new KustoConnectionStringBuilder(@"[cluster]")
    		.WithAadAzureTokenCredentialsAuthentication(cred);
    
    

    You need to give the managed identity of your web app access to Azure Data Explorer first.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.