Azure B2C with Native Client - MsalClientException: The server has not found anything matching the requested URI

Viewed 25

Trying to run a basic Azure AD B2C authentication from a Native App. I followed the WPF App registration guidance, and am using extract from the code provided in the Git Hub example.

Using the Microsoft.Identity.Client SDK, when I run await app.AcquireTokenInteractive(App.ApiScopes).ExecuteAsync();, I get the following exception:

Microsoft.Identity.Client.MsalClientException: 'The browser based authentication dialog failed to complete. Reason: The server has not found anything matching the requested URI (Uniform Resource Identifier).'

I run this from an test with NUnit.net

I did the following tries and checks:

  • Tried the recommended URI: https://mytenanturl.com.b2clogin.com/oauth2/nativeclient

  • Tried a custom URI such as https://mytenanturl.com/test/auth/nativeclient

  • Tried a custom URI such as uri://mytenanturl.com/test/auth/nativeclient

  • Tried one of the 3 URIs pre-registered by default on Azure: https://login.microsoftonline.com/common/oauth2/nativeclient

  • Tried with a local URI such as https://127.0.0.1/dev/

  • These URIs are all registered on the Azure Portal / App Registration / Authentication, with Platform Configuration set to Mobile and desktop applications

  • In the App Regsitration Manifest, it says

    "replyUrlsWithType": [ { "url": "https://127.0.0.1/dev", "type": "InstalledClient" }, { "url": "https://login.microsoftonline.com/common/oauth2/nativeclient", "type": "InstalledClient" }, etc,

  • When I inspect the IPublicClientApplication object, I can see the URI correctly inclued within .AppConfig.RedirectUri. However, PublicClientApplication.RedirectUri says it is Null. I am confused beause I cannot even understand where this property is comming from, since it does not appear in the documentation, where PublicClientApplication Class or its parent classes have no RedirectUri property.

What am I doing wrong?

1 Answers

The sample provided in the Ms Documentation shows the client builder invoking .WithB2CAuthority(AuthoritySignUpSignIn), which is not correct.

The QuickStart blade in the Azure AD App Registration page shows to use WithAuthority(AzureCloudInstance.AzurePublic, Tenant) where Tenant can be companyurl.com or the Directory (tenant) Id provided on the overview page of the App Registration.

Related