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

Hannu S 6 Reputation points
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,
Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Developer technologies | C#
Developer technologies | 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.
{count} votes

1 answer

Sort by: Most helpful
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,536 Reputation points Moderator
    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.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.