Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When deployed to Azure I get: "the app is unable to listen on the specified URL"" #3

Open
MarkEvans8 opened this issue Sep 29, 2024 · 3 comments

Comments

@MarkEvans8
Copy link

I've been stuck on this problem for a week and I have no idea what to try next. I've checked all the configuration. It works fine on my local machine but when deployed to Azure I get the error:

MSAL.NetCore.4.64.1.0.MsalClientException:
    ErrorCode: http_listener_error
Microsoft.Identity.Client.MsalClientException: An HttpListenerException occurred 
while listening on http://localhost:52140/ for the system 
browser to complete the login. 
Possible cause and mitigation: the app is unable to listen on the specified URL; 
run 'netsh http add iplisten 127.0.0.1' from the Admin command prompt.
 ---> System.Net.HttpListenerException (5): Access is denied.

The error is raised on this line of code:

PCA = PublicClientApplicationBuilder
    .Create(_settings?.ClientId)
    .WithB2CAuthority(_settings?.Authority)
    .WithRedirectUri("http://localhost")
    .Build();

Help!!!!!!!

@carlfranklin
Copy link
Owner

carlfranklin commented Sep 29, 2024 via email

@MarkEvans8
Copy link
Author

MarkEvans8 commented Sep 29, 2024

Thanks for the help Carl. I really appreciate it. And also thanks for all your help over the last 20 years or so. I started my career with DotNetRocks at the beginning of DotNet and you've been a huge inspiration all these years.

I really don't know what I'm doing wrong here. I changed the above code to:

.WithRedirectUri("https://msalauthinmauikae.azurewebsites.net")

I also tried putting this URI in the "Single Page Application Redirect URIs" and also the "Web Redirect URIs".

When running the app either locally or remotely I get:

MsalClientException: ErrorCode: loopback_redirect_uri
Microsoft.Identity.Client.MsalClientException: 
Only loopback redirect uri is supported, but https://msalauthinmauikae.azurewebsites.net/ was found. 
Configure http://localhost or http://localhost:port both during app registration 
and when you create the PublicClientApplication object. 
See https://aka.ms/msal-net-os-browser for details

I've tried setting http://localhost:1234 in the app and in the AD settings but that doesn't seem to work either. Tomorrow I'll start all over and download your code and configure AD from scratch. Then I'll try your suggestion again. I've messed around with so much stuff in the last week that maybe I've changed up some other setting.

Thanks again Carl. Love your work!

@MarkEvans8
Copy link
Author

MarkEvans8 commented Oct 1, 2024

I've just gone through this again and the result was the same. I followed these steps:

  1. I cloned this repo and went through the video (https://www.youtube.com/watch?v=AlRxwIOq4jQ) to set up Azure. I was very careful to get everything right. I didn't upgrade the code to .NET 8 or update any of the NuGet packages.

  2. It worked locally but failed when deployed to Azure.

  3. I added error handling to MainLayout.razor so it displays exceptions.

  4. The error was:

An HttpListenerException occurred while listening on 
http://localhost:50215/ for the system browser to complete the login.
  1. In my AD configuration I had entered "http://localhost" in the Single-page application Redirect URIs as instructed in the video. I added this URI:
    https://msalauthinblazoroct1.azurewebsites.net

  2. I tested the app and the same error occurred.

  3. I changed the code in PCAWrapper.cs from this:

.WithRedirectUri("http://localhost")

to this:

.WithRedirectUri("https://msalauthinblazoroct1.azurewebsites.net")
  1. I tested the app and got this error:
MsalClientException: Only loopback redirect uri is supported, 
but https://msalauthinblazoroct1.azurewebsites.net/ was found. 
Configure http://localhost or http://localhost:port both during app 
registration and when you create the PublicClientApplication object. 
See https://aka.ms/msal-net-os-browser for details.
  1. I also tried entering "https://msalauthinblazoroct1.azurewebsites.net" in the Web Redirect URIs but that didn't make any difference.

I'm completely out of ideas now :(

Please help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants