AADSTS50049 error using Microsoft.identity.Client, api is public so...

Hannu S 1 Reputation point
2023-03-22T15:03:55.6833333+00:00

Tried a lot of different things, but I probably have somehthing wrong on my mind...

Some help would be great.

Error:

AADSTS50049: Unknown or invalid instance.

Trace ID: e438b040-a6a5-498f-adf8-791940c71600

Correlation ID: a5bb4fa8-4d4b-477f-8a6c-aef8f577bc2a

Timestamp: 2023-03-22 14:48:54Z

Code:


AADSTS50049: Unknown or invalid instance.
Trace ID: e438b040-a6a5-498f-adf8-791940c71600
Correlation ID: a5bb4fa8-4d4b-477f-8a6c-aef8f577bc2a
Timestamp: 2023-03-22 14:48:54Z
Code:

var clientId = Guid.NewGuid().ToString(); 
            var policy = "B2C_1_Policy";
            var redirecturi = "https://online-genesis-serviceapi.azurewebsites.net";
            var authority = "https://thermialogin.b2clogin.com/thermialogin.onmicrosoft.com/B2C_1A_SignUpOrSigninOnline/";
            //var pca = new PublicClientApplication(clientid, authority) { RedirectUri = redirecturi };
            string[] scopes = new string[] { "*" };
            IPublicClientApplication app;
            app = PublicClientApplicationBuilder.Create(clientId)
                                  .WithAuthority(authority)

                                  .Build();
            // var accounts = await app.GetAccountsAsync();
            AuthenticationResult result = null;
            try
            {
                result = await app.AcquireTokenByUsernamePassword(scopes,
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,239 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,639 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 2023-03-23T06:13:16.5233333+00:00

    Hello @Hannu S , to avoid getting the AADSTS50049: Unknown or invalid instance error you need to replace the WithAuthority(string) call with WithB2CAuthority(string) which is B2C specific. For more information take a look to Authority for an Azure AD B2C tenant and policy.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing similar issues can more easily find a solution.

    1 person found this answer helpful.