{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Security/pulls/comments/30438132","id":30438132,"diff_hunk":"@@ -159,14 +160,44 @@ protected override AuthenticationTicket AuthenticateCore()\n             return new TokenResponse(oauth2Token);\n         }\n \n-        protected virtual async Task<AuthenticationTicket> GetUserInformationAsync(AuthenticationProperties properties, TokenResponse tokens)\n+        protected virtual async Task<AuthenticationTicket> CreateTicketAsync(AuthenticationProperties properties, TokenResponse tokens)\n         {\n-            var context = new OAuthGetUserInformationContext(Context, Options, Backchannel, tokens)\n+            var identity = new ClaimsIdentity(Options.AuthenticationScheme);\n+\n+            if (Options.SaveTokens)\n             {\n-                Properties = properties,\n+                identity.AddClaim(new Claim(\"access_token\", tokens.AccessToken, ClaimValueTypes.String, Options.ClaimsIssuer));\n+\n+                if (!string.IsNullOrEmpty(tokens.RefreshToken))\n+                {\n+                    identity.AddClaim(new Claim(\"refresh_token\", tokens.RefreshToken, ClaimValueTypes.String, Options.ClaimsIssuer));\n+                }\n+\n+                if (!string.IsNullOrEmpty(tokens.TokenType))\n+                {\n+                    identity.AddClaim(new Claim(\"token_type\", tokens.TokenType, ClaimValueTypes.String, Options.ClaimsIssuer));\n+                }\n+\n+                if (!string.IsNullOrEmpty(tokens.ExpiresIn))\n+                {\n+                    identity.AddClaim(new Claim(\"expires_in\", tokens.ExpiresIn, ClaimValueTypes.String, Options.ClaimsIssuer));\n+                }\n+            }\n+\n+            var notification = new OAuthGetUserInformationContext(Context, Options, Backchannel, tokens)\n+            {\n+                Principal = new ClaimsPrincipal(identity),\n+                Properties = properties\n             };\n-            await Options.Notifications.GetUserInformationAsync(context);\n-            return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme);\n+            \n+            await Options.Notifications.GetUserInformationAsync(notification);","path":"src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs","position":56,"original_position":56,"commit_id":"a832769bfbf807769a5ef955305d4dd0b4b74e50","original_commit_id":"a832769bfbf807769a5ef955305d4dd0b4b74e50","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 also be renamed?","created_at":"2015-05-15T19:24:39Z","updated_at":"2015-05-15T19:24:39Z","html_url":"https://github.com/aspnet/Security/pull/257#discussion_r30438132","pull_request_url":"https://api.github.com/repos/aspnet/Security/pulls/257","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Security/pulls/comments/30438132"},"html":{"href":"https://github.com/aspnet/Security/pull/257#discussion_r30438132"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Security/pulls/257"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Security/pulls/257","id":35425985,"html_url":"https://github.com/aspnet/Security/pull/257","diff_url":"https://github.com/aspnet/Security/pull/257.diff","patch_url":"https://github.com/aspnet/Security/pull/257.patch","issue_url":"https://api.github.com/repos/aspnet/Security/issues/257","number":257,"state":"open","locked":false,"title":"Add a new SaveTokens option to save access and tokens directly in OAuthAuthenticationHandler","user":{"login":"PinpointTownes","id":6998306,"avatar_url":"https://avatars.githubusercontent.com/u/6998306?v=3","gravatar_id":"","url":"https://api.github.com/users/PinpointTownes","html_url":"https://github.com/PinpointTownes","followers_url":"https://api.github.com/users/PinpointTownes/followers","following_url":"https://api.github.com/users/PinpointTownes/following{/other_user}","gists_url":"https://api.github.com/users/PinpointTownes/gists{/gist_id}","starred_url":"https://api.github.com/users/PinpointTownes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PinpointTownes/subscriptions","organizations_url":"https://api.github.com/users/PinpointTownes/orgs","repos_url":"https://api.github.com/users/PinpointTownes/repos","events_url":"https://api.github.com/users/PinpointTownes/events{/privacy}","received_events_url":"https://api.github.com/users/PinpointTownes/received_events","type":"User","site_admin":false},"body":"In the current bits, the OAuth2 client middleware automagically saves access and refresh tokens in the `ClaimsPrincipal` it issues, but this logic disappears when you override the default `OnGetUserInformation` notification: https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationDefaults.cs#L13\r\n\r\nThis pull request removes `DefaultOnGetUserInformationAsync`, moves its logic directly to `OAuthAuthenticationHandler` and adds a new `SaveTokens` property to `OAuthAuthenticationOptions` to decide whether tokens should be stored in `ClaimsPrincipal` (and in the final authentication cookie) or not, independently of the `OnGetUserInformation` notification.\r\n\r\nThis will also make `OAuthAuthenticationHandler` inheritors more DRY, as they won't have to repeat the same snippet again and again: https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/blob/dev/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs#L52-L70\r\n\r\n/cc @HaoK @Tratcher ","created_at":"2015-05-14T14:28:10Z","updated_at":"2015-05-15T19:24:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88b3c31040d2c325d892262b60f303bc5674c29b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Security/pulls/257/commits","review_comments_url":"https://api.github.com/repos/aspnet/Security/pulls/257/comments","review_comment_url":"https://api.github.com/repos/aspnet/Security/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/Security/issues/257/comments","statuses_url":"https://api.github.com/repos/aspnet/Security/statuses/a832769bfbf807769a5ef955305d4dd0b4b74e50","head":{"label":"PinpointTownes:oauth","ref":"oauth","sha":"a832769bfbf807769a5ef955305d4dd0b4b74e50","user":{"login":"PinpointTownes","id":6998306,"avatar_url":"https://avatars.githubusercontent.com/u/6998306?v=3","gravatar_id":"","url":"https://api.github.com/users/PinpointTownes","html_url":"https://github.com/PinpointTownes","followers_url":"https://api.github.com/users/PinpointTownes/followers","following_url":"https://api.github.com/users/PinpointTownes/following{/other_user}","gists_url":"https://api.github.com/users/PinpointTownes/gists{/gist_id}","starred_url":"https://api.github.com/users/PinpointTownes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PinpointTownes/subscriptions","organizations_url":"https://api.github.com/users/PinpointTownes/orgs","repos_url":"https://api.github.com/users/PinpointTownes/repos","events_url":"https://api.github.com/users/PinpointTownes/events{/privacy}","received_events_url":"https://api.github.com/users/PinpointTownes/received_events","type":"User","site_admin":false},"repo":{"id":30196509,"name":"Security","full_name":"PinpointTownes/Security","owner":{"login":"PinpointTownes","id":6998306,"avatar_url":"https://avatars.githubusercontent.com/u/6998306?v=3","gravatar_id":"","url":"https://api.github.com/users/PinpointTownes","html_url":"https://github.com/PinpointTownes","followers_url":"https://api.github.com/users/PinpointTownes/followers","following_url":"https://api.github.com/users/PinpointTownes/following{/other_user}","gists_url":"https://api.github.com/users/PinpointTownes/gists{/gist_id}","starred_url":"https://api.github.com/users/PinpointTownes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PinpointTownes/subscriptions","organizations_url":"https://api.github.com/users/PinpointTownes/orgs","repos_url":"https://api.github.com/users/PinpointTownes/repos","events_url":"https://api.github.com/users/PinpointTownes/events{/privacy}","received_events_url":"https://api.github.com/users/PinpointTownes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PinpointTownes/Security","description":"Middleware for security and authorization of web apps.","fork":true,"url":"https://api.github.com/repos/PinpointTownes/Security","forks_url":"https://api.github.com/repos/PinpointTownes/Security/forks","keys_url":"https://api.github.com/repos/PinpointTownes/Security/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PinpointTownes/Security/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PinpointTownes/Security/teams","hooks_url":"https://api.github.com/repos/PinpointTownes/Security/hooks","issue_events_url":"https://api.github.com/repos/PinpointTownes/Security/issues/events{/number}","events_url":"https://api.github.com/repos/PinpointTownes/Security/events","assignees_url":"https://api.github.com/repos/PinpointTownes/Security/assignees{/user}","branches_url":"https://api.github.com/repos/PinpointTownes/Security/branches{/branch}","tags_url":"https://api.github.com/repos/PinpointTownes/Security/tags","blobs_url":"https://api.github.com/repos/PinpointTownes/Security/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PinpointTownes/Security/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PinpointTownes/Security/git/refs{/sha}","trees_url":"https://api.github.com/repos/PinpointTownes/Security/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PinpointTownes/Security/statuses/{sha}","languages_url":"https://api.github.com/repos/PinpointTownes/Security/languages","stargazers_url":"https://api.github.com/repos/PinpointTownes/Security/stargazers","contributors_url":"https://api.github.com/repos/PinpointTownes/Security/contributors","subscribers_url":"https://api.github.com/repos/PinpointTownes/Security/subscribers","subscription_url":"https://api.github.com/repos/PinpointTownes/Security/subscription","commits_url":"https://api.github.com/repos/PinpointTownes/Security/commits{/sha}","git_commits_url":"https://api.github.com/repos/PinpointTownes/Security/git/commits{/sha}","comments_url":"https://api.github.com/repos/PinpointTownes/Security/comments{/number}","issue_comment_url":"https://api.github.com/repos/PinpointTownes/Security/issues/comments{/number}","contents_url":"https://api.github.com/repos/PinpointTownes/Security/contents/{+path}","compare_url":"https://api.github.com/repos/PinpointTownes/Security/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PinpointTownes/Security/merges","archive_url":"https://api.github.com/repos/PinpointTownes/Security/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PinpointTownes/Security/downloads","issues_url":"https://api.github.com/repos/PinpointTownes/Security/issues{/number}","pulls_url":"https://api.github.com/repos/PinpointTownes/Security/pulls{/number}","milestones_url":"https://api.github.com/repos/PinpointTownes/Security/milestones{/number}","notifications_url":"https://api.github.com/repos/PinpointTownes/Security/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PinpointTownes/Security/labels{/name}","releases_url":"https://api.github.com/repos/PinpointTownes/Security/releases{/id}","created_at":"2015-02-02T16:36:08Z","updated_at":"2015-04-18T16:42:37Z","pushed_at":"2015-05-14T15:51:09Z","git_url":"git://github.com/PinpointTownes/Security.git","ssh_url":"git@github.com:PinpointTownes/Security.git","clone_url":"https://github.com/PinpointTownes/Security.git","svn_url":"https://github.com/PinpointTownes/Security","homepage":"","size":1323,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"468852550cfc467f5cb80bcf86e394cd48fe4e7c","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-05-14T19:19:37Z","pushed_at":"2015-05-15T06:00:45Z","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":5270,"stargazers_count":136,"watchers_count":136,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":63,"mirror_url":null,"open_issues_count":55,"forks":63,"open_issues":55,"watchers":136,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Security/pulls/257"},"html":{"href":"https://github.com/aspnet/Security/pull/257"},"issue":{"href":"https://api.github.com/repos/aspnet/Security/issues/257"},"comments":{"href":"https://api.github.com/repos/aspnet/Security/issues/257/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Security/pulls/257/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Security/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Security/pulls/257/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Security/statuses/a832769bfbf807769a5ef955305d4dd0b4b74e50"}}}}