Search code examples
c#wpfazureazure-ad-msal.net-core-3.0

To authenticate .NET Core 3.0 WPF desktop client with AD B2C, how to use the Default OS Browser?


I am creating a new WPF .NET Core 3.0 app, using Microsoft Identity Client (4.0.0), and want to authenticate using AD B2C to gain access to a Web API.

I have registered the app with the AD B2C tenant. But the call to AcquireTokenInteractive is throwing an exception indicating

"Only loopback redirect uri is supported, but urn:ietf:wg:oauth:2.0:oob 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".

// Creation of PublicClientApp
// Call to WithRedirectUri is commented out because that redirect URI cannot
// be added during app registration. 
public static IPublicClientApplication PublicClientApp { get; } = PublicClientApplicationBuilder.
    Create(ClientId).
    WithB2CAuthority(Authority).
    // WithRedirectUri("http://localhost").
    Build();
// Sign-in method logic
await App.PublicClientApp.AcquireTokenInteractive(App.ApiScopes).
    WithB2CAuthority(App.Authority).
    WithPrompt(Prompt.SelectAccount).
    ExecuteAsync();

On the AD B2C app registration I cannot add custom URI "http://localhost". Is this scenario not supported? What other options can I use?

Here is the Azure portal AD B2C tenant app registration screen for native client Native app registration screen shot


Solution

  • B2C does not currently support this mode of authentication.

    enter image description here

    You can refer to this document for the authentication.