|
| 1 | +--- |
| 2 | +title: Infinite redirection between OpenID Connect app and Entra ID |
| 3 | +description: Guidance for troubleshooting infinite redirection between 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 | +# Troubleshooting infinite redirection between OIDC app and Entra ID |
| 11 | + |
| 12 | +This article describes an infinite redirection issue between an OpenID Connect (OIDC) application and Microsoft Entra ID. |
| 13 | + |
| 14 | +## Symptoms |
| 15 | + |
| 16 | +When you browse to a website that is built by using an OpenID Connect (OIDC) app with Microsoft Entra ID, the browser enters an infinite loop between the website and Microsoft Entra ID authentication process. |
| 17 | + |
| 18 | +The problem specifically occurs when you start browsing the website using the HTTP protocol. When using HTTPS, the issue doesn't occur. |
| 19 | + |
| 20 | +## Cause |
| 21 | + |
| 22 | +The `.AspNet.Cookies` cookie that stores the access token isn't sent in HTTP requests due to its secure attribute. |
| 23 | + |
| 24 | +## Solution |
| 25 | + |
| 26 | +### Recommended Fix: Enforce HTTPS Navigation |
| 27 | + |
| 28 | +To resolve the issue, enforce HTTPS navigation for the site. HTTPS is always recommended for sites requiring authentication. |
| 29 | + |
| 30 | +### Workaround |
| 31 | + |
| 32 | +If your scenario requires the initial navigation to happen over http, you can customize the Cookies Authentication middleware to allow the authentication AspNet cookie for both HTTP and HTTPS scheme by setting the `CookieSecure` attribute to `CookieSecureOption.Never` as followed in the `Startup.Auth.cs` file: |
| 33 | + |
| 34 | +> [!Note] |
| 35 | +> This workaround isn't recommended for production environments as it compromises security by allowing cookies to be sent over HTTP. |
| 36 | +
|
| 37 | +```csharp |
| 38 | +public void ConfigureAuth(IAppBuilder app) |
| 39 | + { |
| 40 | + app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); |
| 41 | + app.UseCookieAuthentication(new CookieAuthenticationOptions |
| 42 | + { |
| 43 | + CookieSecure = CookieSecureOption.Never |
| 44 | + }); |
| 45 | + |
| 46 | + app.UseOpenIdConnectAuthentication( |
| 47 | + new OpenIdConnectAuthenticationOptions |
| 48 | + { |
| 49 | + ClientId = clientId, |
| 50 | + Authority = authority, |
| 51 | + |
| 52 | +} |
| 53 | + } |
| 54 | +``` |
| 55 | + |
| 56 | +This issue is also discussed in the following GitHub issue: [ASP.NET Issue #219](https://github.com/aspnet/Security/issues/219). |
| 57 | +
|
| 58 | +[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)] |
0 commit comments