{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Security/pulls/comments/33094132","id":33094132,"diff_hunk":"@@ -223,171 +172,62 @@ public AuthenticationTicket Authenticate()\n         /// This method should always be called instead of calling AuthenticateCore directly.\n         /// </summary>\n         /// <returns>The ticket data provided by the authentication logic</returns>\n-        public Task<AuthenticationTicket> AuthenticateAsync()\n-        {\n-            return LazyInitializer.EnsureInitialized(\n-                ref _authenticate,\n-                ref _authenticateInitialized,\n-                ref _authenticateSyncLock,\n-                AuthenticateCoreAsync);\n-        }\n-\n-        /// <summary>\n-        /// The core authentication logic which must be provided by the handler. Will be invoked at most\n-        /// once per request. Do not call directly, call the wrapping Authenticate method instead.\n-        /// </summary>\n-        /// <returns>The ticket data provided by the authentication logic</returns>\n-        protected virtual Task<AuthenticationTicket> AuthenticateCoreAsync()\n-        {\n-            return Task.FromResult(AuthenticateCore());\n-        }\n+        public abstract Task<AuthenticationTicket> AuthenticateAsync();\n \n-        private void ApplyResponse()\n+        public bool ShouldHandleScheme(string authenticationScheme)\n         {\n-            // If ApplyResponse already failed in the OnSendingHeaderCallback or TeardownAsync code path then a\n-            // failed task is cached. If called again the same error will be re-thrown. This breaks error handling\n-            // scenarios like the ability to display the error page or re-execute the request.\n-            try\n-            {\n-                if (!Faulted)\n-                {\n-                    LazyInitializer.EnsureInitialized(\n-                        ref _applyResponse,\n-                        ref _applyResponseInitialized,\n-                        ref _applyResponseSyncLock,\n-                        () =>\n-                        {\n-                            ApplyResponseCore();\n-                            return Task.FromResult(0);\n-                        }).GetAwaiter().GetResult(); // Block if the async version is in progress.\n-                }\n-            }\n-            catch (Exception)\n-            {\n-                Faulted = true;\n-                throw;\n-            }\n-        }\n-\n-        protected virtual void ApplyResponseCore()\n-        {\n-            ApplyResponseGrant();\n-            ApplyResponseChallenge();\n-        }\n-\n-        /// <summary>\n-        /// Causes the ApplyResponseCore to be invoked at most once per request. This method will be\n-        /// invoked either earlier, when the response headers are sent as a result of a response write or flush,\n-        /// or later, as the last step when the original async call to the middleware is returning.\n-        /// </summary>\n-        /// <returns></returns>\n-        private async Task ApplyResponseAsync()\n-        {\n-            // If ApplyResponse already failed in the OnSendingHeaderCallback or TeardownAsync code path then a\n-            // failed task is cached. If called again the same error will be re-thrown. This breaks error handling\n-            // scenarios like the ability to display the error page or re-execute the request.\n-            try\n-            {\n-                if (!Faulted)\n-                {\n-                    await LazyInitializer.EnsureInitialized(\n-                        ref _applyResponse,\n-                        ref _applyResponseInitialized,\n-                        ref _applyResponseSyncLock,\n-                        ApplyResponseCoreAsync);\n-                }\n-            }\n-            catch (Exception)\n-            {\n-                Faulted = true;\n-                throw;\n-            }\n-        }\n-\n-        /// <summary>\n-        /// Core method that may be overridden by handler. The default behavior is to call two common response \n-        /// activities, one that deals with sign-in/sign-out concerns, and a second to deal with 401 challenges.\n-        /// </summary>\n-        /// <returns></returns>\n-        protected virtual async Task ApplyResponseCoreAsync()\n-        {\n-            await ApplyResponseGrantAsync();\n-            await ApplyResponseChallengeAsync();\n-        }\n-\n-        protected abstract void ApplyResponseGrant();\n-\n-        /// <summary>\n-        /// Override this method to dela with sign-in/sign-out concerns, if an authentication scheme in question\n-        /// deals with grant/revoke as part of it's request flow. (like setting/deleting cookies)\n-        /// </summary>\n-        /// <returns></returns>\n-        protected virtual Task ApplyResponseGrantAsync()\n-        {\n-            ApplyResponseGrant();\n-            return Task.FromResult(0);\n+            return string.Equals(BaseOptions.AuthenticationScheme, authenticationScheme, StringComparison.Ordinal) ||\n+                (BaseOptions.AutomaticAuthentication && string.IsNullOrWhiteSpace(authenticationScheme));\n         }\n \n-        public virtual void SignIn(SignInContext context)\n+        public async Task SignInAsync(SignInContext context)\n         {\n             if (ShouldHandleScheme(context.AuthenticationScheme))\n             {\n-                SignInContext = context;\n-                SignOutContext = null;\n+                SignInCalled = true;","path":"src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs","position":317,"original_position":317,"commit_id":"d4df1ed674c282b955b0ca97b72c511534fed434","original_commit_id":"d4df1ed674c282b955b0ca97b72c511534fed434","user":{"login":"Tratcher","id":1821173,"avatar_url":"https://avatars.githubusercontent.com/u/1821173?v=3","gravatar_id":"","url":"https://api.github.com/users/Tratcher","html_url":"https://github.com/Tratcher","followers_url":"https://api.github.com/users/Tratcher/followers","following_url":"https://api.github.com/users/Tratcher/following{/other_user}","gists_url":"https://api.github.com/users/Tratcher/gists{/gist_id}","starred_url":"https://api.github.com/users/Tratcher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tratcher/subscriptions","organizations_url":"https://api.github.com/users/Tratcher/orgs","repos_url":"https://api.github.com/users/Tratcher/repos","events_url":"https://api.github.com/users/Tratcher/events{/privacy}","received_events_url":"https://api.github.com/users/Tratcher/received_events","type":"User","site_admin":false},"body":"Should this be SignInAccepted?","created_at":"2015-06-23T21:21:42Z","updated_at":"2015-06-23T21:21:42Z","html_url":"https://github.com/aspnet/Security/pull/283#discussion_r33094132","pull_request_url":"https://api.github.com/repos/aspnet/Security/pulls/283","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Security/pulls/comments/33094132"},"html":{"href":"https://github.com/aspnet/Security/pull/283#discussion_r33094132"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Security/pulls/283"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Security/pulls/283","id":36990464,"html_url":"https://github.com/aspnet/Security/pull/283","diff_url":"https://github.com/aspnet/Security/pull/283.diff","patch_url":"https://github.com/aspnet/Security/pull/283.patch","issue_url":"https://api.github.com/repos/aspnet/Security/issues/283","number":283,"state":"open","locked":false,"title":"AuthenticationHandler now fully Async, SignOut/SignIn/Challenge API changes ","user":{"login":"HaoK","id":6537861,"avatar_url":"https://avatars.githubusercontent.com/u/6537861?v=3","gravatar_id":"","url":"https://api.github.com/users/HaoK","html_url":"https://github.com/HaoK","followers_url":"https://api.github.com/users/HaoK/followers","following_url":"https://api.github.com/users/HaoK/following{/other_user}","gists_url":"https://api.github.com/users/HaoK/gists{/gist_id}","starred_url":"https://api.github.com/users/HaoK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaoK/subscriptions","organizations_url":"https://api.github.com/users/HaoK/orgs","repos_url":"https://api.github.com/users/HaoK/repos","events_url":"https://api.github.com/users/HaoK/events{/privacy}","received_events_url":"https://api.github.com/users/HaoK/received_events","type":"User","site_admin":false},"body":"Depends on https://github.com/aspnet/HttpAbstractions/pull/323\r\n\r\n## Overview of AuthenticationHandler changes:\r\n- Response is mutated directly as part of SignIn/SignOut Challenge invocation (instead of on Teardown)\r\n- Consume ChallengeBehavior: \r\n   Automatic means (403 if Authenticate produces an identity, 401 otherwise)\r\n   Unauthorized/Forbidden explicitly call the appropriate code path\r\n- new ChallengeCalled flag so ApplyResponseChallenge is only called once\r\n- Cookie now overrides TeardownAsync to continue the old renew/refresh behavior\r\n\r\n## New protected virtual methods\r\n- HandleChallenge: default behavior for implementing the ChallengeBehavior functionality\r\n- HandleUnauthorized: (turns around and just calls the existing ApplyResponseChallenge)\r\n- HandleForbidden: sets 403 by default, Cookie overrides to add support for AccessDenied redirect page\r\n- HandleSignIn/Out: lifted out of ApplyResponseGrant, now done immediately\r\n\r\n## TODO:\r\n- Its still a bit messy in AuthenticationHandler, need to iterate on that more\r\n- Lou wants the AuthenticationManager.Challenge setting of 401 to move into the handler (that change currently doesn't completely work with the passive challenge flow intercepting 401s)\r\n\r\ncc @lodejard @Tratcher @blowdart @divega @davidfowl @muratg \r\n\r\n","created_at":"2015-06-05T00:03:04Z","updated_at":"2015-06-23T21:21:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ef9c83572c76784aa8d195eb727fac20f48da391","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Security/pulls/283/commits","review_comments_url":"https://api.github.com/repos/aspnet/Security/pulls/283/comments","review_comment_url":"https://api.github.com/repos/aspnet/Security/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/Security/issues/283/comments","statuses_url":"https://api.github.com/repos/aspnet/Security/statuses/d4df1ed674c282b955b0ca97b72c511534fed434","head":{"label":"aspnet:haok/6-3challenge","ref":"haok/6-3challenge","sha":"d4df1ed674c282b955b0ca97b72c511534fed434","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":17723699,"name":"Security","full_name":"aspnet/Security","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Security","description":"Middleware for security and authorization of web apps.","fork":false,"url":"https://api.github.com/repos/aspnet/Security","forks_url":"https://api.github.com/repos/aspnet/Security/forks","keys_url":"https://api.github.com/repos/aspnet/Security/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Security/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Security/teams","hooks_url":"https://api.github.com/repos/aspnet/Security/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Security/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Security/events","assignees_url":"https://api.github.com/repos/aspnet/Security/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Security/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Security/tags","blobs_url":"https://api.github.com/repos/aspnet/Security/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Security/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Security/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Security/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Security/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Security/languages","stargazers_url":"https://api.github.com/repos/aspnet/Security/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Security/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Security/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Security/subscription","commits_url":"https://api.github.com/repos/aspnet/Security/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Security/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Security/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Security/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Security/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Security/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Security/merges","archive_url":"https://api.github.com/repos/aspnet/Security/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Security/downloads","issues_url":"https://api.github.com/repos/aspnet/Security/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Security/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Security/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Security/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Security/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Security/releases{/id}","created_at":"2014-03-13T19:44:34Z","updated_at":"2015-06-19T20:07:14Z","pushed_at":"2015-06-23T21:21:07Z","git_url":"git://github.com/aspnet/Security.git","ssh_url":"git@github.com:aspnet/Security.git","clone_url":"https://github.com/aspnet/Security.git","svn_url":"https://github.com/aspnet/Security","homepage":"","size":4793,"stargazers_count":154,"watchers_count":154,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":66,"forks":66,"open_issues":66,"watchers":154,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"ab3cc8bcc77eb3983e93c4c12a74f42223b48476","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":17723699,"name":"Security","full_name":"aspnet/Security","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Security","description":"Middleware for security and authorization of web apps.","fork":false,"url":"https://api.github.com/repos/aspnet/Security","forks_url":"https://api.github.com/repos/aspnet/Security/forks","keys_url":"https://api.github.com/repos/aspnet/Security/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Security/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Security/teams","hooks_url":"https://api.github.com/repos/aspnet/Security/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Security/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Security/events","assignees_url":"https://api.github.com/repos/aspnet/Security/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Security/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Security/tags","blobs_url":"https://api.github.com/repos/aspnet/Security/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Security/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Security/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Security/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Security/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Security/languages","stargazers_url":"https://api.github.com/repos/aspnet/Security/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Security/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Security/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Security/subscription","commits_url":"https://api.github.com/repos/aspnet/Security/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Security/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Security/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Security/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Security/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Security/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Security/merges","archive_url":"https://api.github.com/repos/aspnet/Security/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Security/downloads","issues_url":"https://api.github.com/repos/aspnet/Security/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Security/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Security/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Security/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Security/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Security/releases{/id}","created_at":"2014-03-13T19:44:34Z","updated_at":"2015-06-19T20:07:14Z","pushed_at":"2015-06-23T21:21:07Z","git_url":"git://github.com/aspnet/Security.git","ssh_url":"git@github.com:aspnet/Security.git","clone_url":"https://github.com/aspnet/Security.git","svn_url":"https://github.com/aspnet/Security","homepage":"","size":4793,"stargazers_count":154,"watchers_count":154,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":66,"forks":66,"open_issues":66,"watchers":154,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Security/pulls/283"},"html":{"href":"https://github.com/aspnet/Security/pull/283"},"issue":{"href":"https://api.github.com/repos/aspnet/Security/issues/283"},"comments":{"href":"https://api.github.com/repos/aspnet/Security/issues/283/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Security/pulls/283/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Security/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Security/pulls/283/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Security/statuses/d4df1ed674c282b955b0ca97b72c511534fed434"}}}}