0

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

  • Are you sure you can use http://myWebAppUrl but not the https here? It may not relate to the issue itself... – Tiny Wang Dec 07 '21 at 10:01

1 Answers1

0

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
kavyaS
  • 8,026
  • 1
  • 7
  • 19