title: .Net Core Azure AD authentication failes since Hybrid Active Directory
body: <p>I have a .Net Core 5 MVC application that uses Azure AD and 2FA for authentication. This has worked perfectly for a long time.</p>
  <p>But now we switched to <a href="https://docs.microsoft.com/en-us/azure/active-directory/devices/hybrid-azuread-join-managed-domains" rel="nofollow noreferrer">Hybrid Azure AD</a> and now login is no longer possible in Edge or Chrome.</p>
  <p>I changed nothing to my own code.
  In Startup.cs</p>
  <pre><code> services
      .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
      .AddMicrosoftIdentityWebApp(Configuration.GetSection(&quot;AzureAd&quot;));
  </code></pre>
  <p>in appsettings.json</p>
  <pre><code>&quot;AzureAd&quot;: {
    &quot;Instance&quot;: &quot;https://login.microsoftonline.com&quot;,
    &quot;ClientId&quot;: &quot;***&quot;,
    &quot;TenantId&quot;: &quot;***&quot;,
    &quot;CallbackPath&quot;: &quot;/signin-oidc&quot;,
    &quot;ClientSecret&quot;: &quot;***&quot;,
    &quot;Domain&quot;: &quot;***.onmicrosoft.com&quot;
  }
  </code></pre>
  <p>The nuget identity packages used are Microsoft.Identity.Web and Microsoft.Identity.web.UI</p>
  <p>When using Firefox everything works like before. I can login with 2FA and everything works fine. But Chrome and Edge give me the problems. An authentication request is sent and it seems to be successfull. When the sysadmin checks in the Azure Portal all authentication requests are marked &quot;Success&quot; but in my application i'm not logged in. I stay on de login page</p>
  <p>When i try a direct page url, the browser tries to log me in multiple times but it ends with the message that i cannot be logged in and to try again later.</p>
  <p>Do i have to make adjustments to my project to work with hybride Azure Active Directory?
  Not sure if more information is needed to make my question more clear</p>
  <p>EDIT: i made some progress but no solution. It seems to involve the Mads Kristensen Service Worker nuget package (<a href="https://github.com/madskristensen/WebEssentials.AspNetCore.ServiceWorker" rel="nofollow noreferrer">LINK</a>). If i remove this package, everything works fine. If active, i have to remove a cookie to get authentication. The next time i open the application, no more authentication until i remove the cookie. It could be a total coincidence and not related</p>
  <p>EDIT 2 : I found <a href="https://github.com/madskristensen/WebEssentials.AspNetCore.ServiceWorker/issues/88" rel="nofollow noreferrer">THIS</a> on the github issues page. I think the issues might be related</p>