|
| 1 | +--- |
| 2 | +title: Infinite redirection between OpenID Connect app and Entra ID |
| 3 | +description: Provides guidance for troubleshooting infinite redirection between the OpenID Connect app and Entra ID. |
| 4 | +ms.date: 12/26/2024 |
| 5 | +ms.author: bachoang |
| 6 | +ms.service: entra-id |
| 7 | +ms.custom: sap:Microsoft Entra App Integration and Development |
| 8 | +--- |
| 9 | + |
| 10 | +# Troubleshoot infinite redirection between OIDC app and Entra ID |
| 11 | + |
| 12 | +This article describes an infinite redirection issue that exists between an OpenID Connect (OIDC) application and Microsoft Entra ID. |
| 13 | + |
| 14 | +## Symptoms |
| 15 | + |
| 16 | +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. |
| 17 | + |
| 18 | +The issue specifically occurs when you browse the website by using the HTTP protocol. When you use HTTPS, the issue doesn't occur. |
| 19 | + |
| 20 | +## Cause |
| 21 | + |
| 22 | +The `.AspNet.Cookies` cookie isn't sent in HTTP requests because of its secure attribute. |
| 23 | + |
| 24 | +## Solution: Enforce HTTPS navigation |
| 25 | + |
| 26 | +To resolve the issue, enforce HTTPS navigation for the site. HTTPS is always recommended for sites that require authentication. |
| 27 | + |
| 28 | +## Workaround |
| 29 | + |
| 30 | +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. |
| 31 | + |
| 32 | +> [!Note] |
| 33 | +> This workaround isn't recommended for production environments because it compromises security by allowing cookies to be sent over HTTP. |
| 34 | +
|
| 35 | +```csharp |
| 36 | +public void ConfigureAuth(IAppBuilder app) |
| 37 | + { |
| 38 | + app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); |
| 39 | + app.UseCookieAuthentication(new CookieAuthenticationOptions |
| 40 | + { |
| 41 | + CookieSecure = CookieSecureOption.Never |
| 42 | + }); |
| 43 | + |
| 44 | + app.UseOpenIdConnectAuthentication( |
| 45 | + new OpenIdConnectAuthenticationOptions |
| 46 | + { |
| 47 | + ClientId = clientId, |
| 48 | + Authority = authority, |
| 49 | + |
| 50 | +} |
| 51 | + } |
| 52 | +``` |
| 53 | + |
| 54 | +This issue is discussed also in [this ASP.NET Security Blog article (Issue #219)](https://github.com/aspnet/Security/issues/219). |
| 55 | +
|
| 56 | +[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)] |
0 commit comments