{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Security/issues/1069","repository_url":"https://api.github.com/repos/aspnet/Security","labels_url":"https://api.github.com/repos/aspnet/Security/issues/1069/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Security/issues/1069/comments","events_url":"https://api.github.com/repos/aspnet/Security/issues/1069/events","html_url":"https://github.com/aspnet/Security/issues/1069","id":195264558,"number":1069,"title":"Unhandled remote failure","user":{"login":"imperugo","id":758620,"avatar_url":"https://avatars.githubusercontent.com/u/758620?v=3","gravatar_id":"","url":"https://api.github.com/users/imperugo","html_url":"https://github.com/imperugo","followers_url":"https://api.github.com/users/imperugo/followers","following_url":"https://api.github.com/users/imperugo/following{/other_user}","gists_url":"https://api.github.com/users/imperugo/gists{/gist_id}","starred_url":"https://api.github.com/users/imperugo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imperugo/subscriptions","organizations_url":"https://api.github.com/users/imperugo/orgs","repos_url":"https://api.github.com/users/imperugo/repos","events_url":"https://api.github.com/users/imperugo/events{/privacy}","received_events_url":"https://api.github.com/users/imperugo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-13T14:18:45Z","updated_at":"2016-12-14T06:15:20Z","closed_at":null,"body":"Hi, \r\nI've an application that is using `UseOpenIdConnectAuthentication` with [IdentityServer 4](https://github.com/IdentityServer/IdentityServer4) and sometimes I get this weird error:\r\n\r\n``` terminal\r\nConnection id \"0HL13A41L8P2I\": An unhandled exception was thrown by the application.\r\nSystem.AggregateException: Unhandled remote failure. ---> System.Exception: Correlation failed.\r\n  --- End of inner exception stack trace ---\r\n  at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRemoteCallbackAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRequestAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.<HandleRequestAsync>d__15.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n  at Gaia.Bmw.Remarketing.Startup.<>c.<<Configure>b__11_0>d.MoveNext() in C:\\Projects\\bmw\\bmw-remarketing\\src\\Gaia.Bmw.Remarketing\\Startup.cs:line 128\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.<Invoke>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n  at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()\r\n---> (Inner Exception #0) System.Exception: Correlation failed.<---\r\n```\r\n\r\nUnfortunately I didn't find a way to replicated the problem, it just comes up into the log randomly.\r\n\r\nHere my configuration\r\n\r\n```csharp\r\nvar oidcOptions = new OpenIdConnectOptions\r\n{\r\n    AuthenticationScheme = \"oidc\",\r\n    ClaimsIssuer = urlBuilderConfiguration.Auth.Url,\r\n    SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme,\r\n    Authority = idsrvConfiguration.IdentityServerEndpoint,\r\n    RequireHttpsMetadata = false,\r\n    PostLogoutRedirectUri = urlBuilder.Home,\r\n    ClientId = idsrvConfiguration.Clients.Remarketing.Id,\r\n    ClientSecret = idsrvConfiguration.Clients.Remarketing.Secret,\r\n    ResponseType = \"code id_token\",\r\n    GetClaimsFromUserInfoEndpoint = true,\r\n    SaveTokens = false, // https://auth0.com/docs/quickstart/webapp/aspnet-core/04-storing-tokens\r\n    Scope =\r\n    {\r\n        idsrvConfiguration.Scopes.Frontoffice,\r\n        \"openid\",\r\n        \"profile\",\r\n        \"email\",\r\n        \"roles\"\r\n    },\r\n    TokenValidationParameters = new TokenValidationParameters\r\n    {\r\n        IssuerSigningKey = new X509SecurityKey(encryptingCertificate)\r\n    },\r\n    Events = new OpenIdConnectEvents\r\n    {\r\n        OnRedirectToIdentityProvider = ctx =>\r\n        {\r\n            // APIs must return 401 not 302\r\n            if (ctx.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication)\r\n            {\r\n                var isAjax = ctx.Request.Headers[\"X-Requested-With\"] == \"XMLHttpRequest\";\r\n\r\n                if (isAjax)\r\n                {\r\n                    ctx.Response.StatusCode = (int) HttpStatusCode.Unauthorized;\r\n                    ctx.HandleResponse();\r\n                    return Task.FromResult(0);\r\n                }\r\n            }\r\n            return Task.FromResult(0);\r\n        }\r\n    }\r\n};\r\n```\r\nI'm running the app on Azure AppService with fw46.\r\nDo you have any hint on how to fix/understand the problem?\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Security/issues/comments/266952177","html_url":"https://github.com/aspnet/Security/issues/1069#issuecomment-266952177","issue_url":"https://api.github.com/repos/aspnet/Security/issues/1069","id":266952177,"user":{"login":"leastprivilege","id":1454075,"avatar_url":"https://avatars.githubusercontent.com/u/1454075?v=3","gravatar_id":"","url":"https://api.github.com/users/leastprivilege","html_url":"https://github.com/leastprivilege","followers_url":"https://api.github.com/users/leastprivilege/followers","following_url":"https://api.github.com/users/leastprivilege/following{/other_user}","gists_url":"https://api.github.com/users/leastprivilege/gists{/gist_id}","starred_url":"https://api.github.com/users/leastprivilege/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leastprivilege/subscriptions","organizations_url":"https://api.github.com/users/leastprivilege/orgs","repos_url":"https://api.github.com/users/leastprivilege/repos","events_url":"https://api.github.com/users/leastprivilege/events{/privacy}","received_events_url":"https://api.github.com/users/leastprivilege/received_events","type":"User","site_admin":false},"created_at":"2016-12-14T06:15:20Z","updated_at":"2016-12-14T06:15:20Z","body":"We are always returning state correctly. Maybe a URL length issue?"}}
{"actor":{"display_login":"leastprivilege"}}