MSAL doesn't pop up when project is published to Azure VM

617 Views Asked by At

Below is my code to popup and login through MSAL.

var app = PublicClientApplicationBuilder.Create(msal.ClientId)
.WithDefaultRedirectUri()
.WithTenantId(msal.TenantId)
.Build();

var result = await app.AcquireTokenInteractive(msal.Scopes).ExecuteAsync();

Code above works when it's running on my local machine.

And below is my settings in Azure AD. Its working when I set it to localhost:5000 enter image description here

But when I set the localhost to 'myWebAppUrl' which is hosted on Azure Virtual Machine. MSAL won't popup. And it will just return "The operation was cancelled". Anything I missed here? enter image description here

1

There are 1 best solutions below

0
kavyaS On

Please check the below points.

  1. In azure ad,the reply URL must begin with the scheme https, unless using localhost. ex:http://localhost:5000 Else you can use something like https://yourappurl and don’t forget to Grant admin consent Under Permissions for the scopes you have in azure ad. Please check Redirect URI restrictions

  2. Apps that use system browsers: http://localhost

    Apps that use embedded browsers:https://login.microsoftonline.com/common/oauth2/nativeclient

    For Node.js, you can use msal://redirect

Please check Add a redirect URI section and Client application configuration (MSAL) | Microsoft Docs And check if you can use confidential client to your app .

Some authentication libraries like MSAL.NET use a default value of urn:ietf:wg:oauth:2.0:oob when no other redirect URI is specified, which is not recommended. This default will be updated as a breaking change in the next major release.

Other references

  1. Instantiate a public client app (MSAL.NET) - Microsoft identity platform | Microsoft Docs
  2. Initialize MSAL.NET client applications - Microsoft identity platform | Microsoft Docs