Summary
This article describes an infinite redirection issue that exists between an OpenID Connect (OIDC) application and Microsoft Entra ID.
Symptoms
When you browse to a website that's built by using an OpenID Connect (OIDC) app and Microsoft Entra ID, the browser enters an infinite loop that forms between the website and the Microsoft Entra ID authentication process.
The issue specifically occurs when you browse the website by using the HTTP protocol. When you use HTTPS, the issue doesn't occur.
Cause
The .AspNet.Cookies cookie isn't sent in HTTP requests because of its secure attribute.
Solution: Enforce HTTPS navigation
To resolve the issue, enforce HTTPS navigation for the site. HTTPS is always recommended for sites that require authentication.
Workaround
If your scenario requires the initial navigation to occur over HTTP, you can customize the Cookies Authentication middleware to allow the authentication AspNet cookie for both the HTTP and HTTPS schemes by setting the CookieSecure attribute to CookieSecureOption.Never, as shown in the following Startup.Auth.cs file.
Note: This workaround isn't recommended for production environments because it compromises security by allowing cookies to be sent over HTTP.
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieSecure = CookieSecureOption.Never
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
}
}
This issue is discussed also in this ASP.NET Security Blog article (Issue #219).
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors (upstream author metadata: bachoang). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
