Search code examples
azure-active-directoryowinazure-ad-msal

OWIN stop functionning in Azure


I got an old application that run for 2 years now without problems. Recently the login part starts to fail with a 404 Not found. Here part of the error:

System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() +94579
Microsoft.IdentityModel.Protocols.<GetDocumentAsync>d__8.MoveNext() +375

[IOException: IDX20804: Unable to retrieve document from: '[PII is hidden]'.]
Microsoft.IdentityModel.Protocols.<GetDocumentAsync>d__8.MoveNext() +663
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
Microsoft.IdentityModel.Protocols.OpenIdConnect.<GetAsync>d__3.MoveNext() +291
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +26
Microsoft.IdentityModel.Protocols.<GetConfigurationAsync>d__24.MoveNext() +1129

The line that create this 404 error not found is: HttpContext.GetOwinContext().Authentication.Challenge(authenticationProperties);

So something changes in Azure Authentication with old MSAL and OWIN authentication (for B2C Azure) In the B2C Azur portal, I can see my apps in Applications (Legacy) with this note: The new App registrations experience is now generally available and is the recommended way of registering applications. Click the App registrations blade to access the new experience. The Applications (Legacy) blade has been deprecated and will no longer be available going forward.

Quite annoying because I do not want to make too much time in development for this old app. I try to found some info for migrating this kind of app. Do I have to only create a new App in AD B2C do I have to change my code? Thanks

EDIT1: That the code called by the login button. All was working couple month ago. I do not change anything or push anything on Azure on this projet for about 2 years!

    public void SignUpSignIn()
    {
        // Use the default policy to process the sign up / sign in flow
        if (!Request.IsAuthenticated)
        {
            string returnUrl = "/";
            if (Request.UrlReferrer.AbsolutePath != null && Request.UrlReferrer.AbsolutePath != "")
                returnUrl = Request.UrlReferrer.AbsolutePath;

            var authenticationProperties = new AuthenticationProperties { RedirectUri = returnUrl };
            HttpContext.GetOwinContext().Authentication.Challenge(authenticationProperties);
            return;
        }

EDIT 2: After adding some PII diagnostique I got this detail: Unable to retrieve document from: 'https://login.microsoftonline.com/tfp/hidenb2c.onmicrosoft.com/B2C_1_SignInOut/v2.0/.well-known/openid-configuration'


Solution

  • Finally, after many tries, I found that I just need to change the URL from

    https://login.microsoftonline.com/tfp/hidenb2c.onmicrosoft.com/B2C_1_SignInOut/v2.0/.well-known/openid-configuration

    to

    https://{tenant}.b2clogin.com/tfp/{tenant}.onmicrosoft.com/B2C_1_SignInOut/v2.0/.well-known/openid-configuration

    now all is working. Thanks for your help.