{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Security/issues/1822","repository_url":"https://api.github.com/repos/aspnet/Security","labels_url":"https://api.github.com/repos/aspnet/Security/issues/1822/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Security/issues/1822/comments","events_url":"https://api.github.com/repos/aspnet/Security/issues/1822/events","html_url":"https://github.com/aspnet/Security/issues/1822","id":342697719,"node_id":"MDU6SXNzdWUzNDI2OTc3MTk=","number":1822,"title":"WsFederation: Error from RemoteAuthentication: Correlation failed - Unhandled exception ","user":{"login":"ManuelHaas","id":10881695,"node_id":"MDQ6VXNlcjEwODgxNjk1","avatar_url":"https://avatars3.githubusercontent.com/u/10881695?v=4","gravatar_id":"","url":"https://api.github.com/users/ManuelHaas","html_url":"https://github.com/ManuelHaas","followers_url":"https://api.github.com/users/ManuelHaas/followers","following_url":"https://api.github.com/users/ManuelHaas/following{/other_user}","gists_url":"https://api.github.com/users/ManuelHaas/gists{/gist_id}","starred_url":"https://api.github.com/users/ManuelHaas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManuelHaas/subscriptions","organizations_url":"https://api.github.com/users/ManuelHaas/orgs","repos_url":"https://api.github.com/users/ManuelHaas/repos","events_url":"https://api.github.com/users/ManuelHaas/events{/privacy}","received_events_url":"https://api.github.com/users/ManuelHaas/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-19T11:57:26Z","updated_at":"2018-07-19T14:01:29Z","closed_at":"2018-07-19T14:01:29Z","author_association":"NONE","body":"Hi,\r\n\r\nI'm using WsFederation for Authentication. After successfully entering AD-Credentials in ADFS-\"screen\". I get the following unhandled exception:\r\n\r\n```\r\nMicrosoft.AspNetCore.Authentication.WsFederation.WsFederationHandler: Warning: '.AspNetCore.Correlation.WsFederation.t2YHE0AeV2eGeqjcV5C5vS-jbt3ggOy3eQ4nmveM27M' cookie not found.\r\nMicrosoft.AspNetCore.Authentication.WsFederation.WsFederationHandler: Information: Error from RemoteAuthentication: Correlation failed..\r\nMicrosoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware: Error: An unhandled exception has occurred while executing the request.\r\n\r\nSystem.Exception: An error was encountered while handling the remote login. ---> System.Exception: Correlation failed.\r\n   --- Ende der internen Ausnahmestapelüberwachung ---\r\n   bei Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRequestAsync>d__12.MoveNext()\r\n--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   bei Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()\r\n--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n   bei Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.<Invoke>d__7.MoveNext()\r\n--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   bei Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()\r\nMicrosoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Information: Route matched with {action = \"Error\", controller = \"Home\"}. Executing action Monitoring.Controllers.HomeController.Error (ToSec.Presentation)\r\nMicrosoft.AspNetCore.Authorization.DefaultAuthorizationService: Information: Authorization failed.\r\nMicrosoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Information: Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.\r\nMicrosoft.AspNetCore.Mvc.ChallengeResult: Information: Executing ChallengeResult with authentication schemes ().\r\nMicrosoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: Information: AuthenticationScheme: Identity.Application was challenged.\r\n```\r\n\r\nHere is the code that is executed for WsFederation auth:\r\n\r\n```c#\r\n[HttpPost]\r\n[AllowAnonymous]\r\n[ValidateAntiForgeryToken]\r\npublic IActionResult ExternalLogin(string provider, string returnUrl = null)\r\n{\r\n\t// Request a redirect to the external login provider.\r\n\tvar redirectUrl = Url.Action(\"ExternalLoginCallback\", \"Account\", new { ReturnUrl = returnUrl });\r\n\tvar properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);\r\n\treturn new ChallengeResult(provider, properties);\r\n}\r\n```\r\n\r\nNote: the callback function will not be entered anymore. Only the unhandled exception is noted in the output window.\r\n\r\nI used the following guide to configure WsFederation: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/ws-federation?view=aspnetcore-2.1\r\n\r\nRelevant code in ConfigureServices:\r\n```c#\r\n...\r\nservices.AddAuthentication()\r\n\t.AddWsFederation(options =>\r\n\t{\r\n\t\t// MetadataAddress represents the Active Directory instance used to authenticate users.\r\n\t\toptions.MetadataAddress = \"https://adfs.XYZ.at/FederationMetadata/2007-06/FederationMetadata.xml\";\r\n\r\n\t\t// Wtrealm is the app's identifier in the Active Directory instance.\r\n\t\t// For ADFS, use the relying party's identifier, its WS-Federation Passive protocol URL:\r\n\t\toptions.Wtrealm = \"https://localhost:44338/\";\r\n\t});\r\n...\r\n```\r\n\r\n### Further technical details\r\nOperating system: Win10 x64\r\nIDE: Visual Studio 2017 15.7.4\r\nAsp.Net Core 2.1.2"},"comment":{"url":"https://api.github.com/repos/aspnet/Security/issues/comments/406286600","html_url":"https://github.com/aspnet/Security/issues/1822#issuecomment-406286600","issue_url":"https://api.github.com/repos/aspnet/Security/issues/1822","id":406286600,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjI4NjYwMA==","user":{"login":"ManuelHaas","id":10881695,"node_id":"MDQ6VXNlcjEwODgxNjk1","avatar_url":"https://avatars3.githubusercontent.com/u/10881695?v=4","gravatar_id":"","url":"https://api.github.com/users/ManuelHaas","html_url":"https://github.com/ManuelHaas","followers_url":"https://api.github.com/users/ManuelHaas/followers","following_url":"https://api.github.com/users/ManuelHaas/following{/other_user}","gists_url":"https://api.github.com/users/ManuelHaas/gists{/gist_id}","starred_url":"https://api.github.com/users/ManuelHaas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManuelHaas/subscriptions","organizations_url":"https://api.github.com/users/ManuelHaas/orgs","repos_url":"https://api.github.com/users/ManuelHaas/repos","events_url":"https://api.github.com/users/ManuelHaas/events{/privacy}","received_events_url":"https://api.github.com/users/ManuelHaas/received_events","type":"User","site_admin":false},"created_at":"2018-07-19T14:01:29Z","updated_at":"2018-07-19T14:01:29Z","author_association":"NONE","body":"Yes, I also added `app.UseCookiePolicy();` in Configure method. Sorry for missing that.\r\n\r\nThe strange thing was that it worked on some clients and on other clients the unhandled exception occured. Maybe regarding some browser security settings."}}
{"actor":{"display_login":"ManuelHaas"}}