{"action":"opened","number":2607,"pull_request":{"url":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/2607","id":214302218,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0MzAyMjE4","html_url":"https://github.com/IdentityServer/IdentityServer4/pull/2607","diff_url":"https://github.com/IdentityServer/IdentityServer4/pull/2607.diff","patch_url":"https://github.com/IdentityServer/IdentityServer4/pull/2607.patch","issue_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues/2607","number":2607,"state":"open","locked":false,"title":"Change: Made DefaultUserSession.AuthenticateAsync overrideable so that","user":{"login":"AndrewMayorov","id":109781,"node_id":"MDQ6VXNlcjEwOTc4MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/109781?v=4","gravatar_id":"","url":"https://api.github.com/users/AndrewMayorov","html_url":"https://github.com/AndrewMayorov","followers_url":"https://api.github.com/users/AndrewMayorov/followers","following_url":"https://api.github.com/users/AndrewMayorov/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMayorov/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMayorov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMayorov/subscriptions","organizations_url":"https://api.github.com/users/AndrewMayorov/orgs","repos_url":"https://api.github.com/users/AndrewMayorov/repos","events_url":"https://api.github.com/users/AndrewMayorov/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMayorov/received_events","type":"User","site_admin":false},"body":"Made DefaultUserSession.AuthenticateAsync overrideable so that  it will be easier to support user impersonation.\r\n\r\n**What issue does this PR address?**\r\nWe need to support impersonations - you are logged in as one user, but then you temporarily switch to another user. Necessary for any setup with a lot of customers, when your support team must be able to act as a user, but you don't want to know everybody's passwords. \r\n\r\nTo support that we have introduced a special cookie with target user name. If cookie is set and real logged in user can impersonate, then user principal in the session gets changed into target user principle. I found no better way of implementing it than to sublcass DefaultUserSession like this:\r\n\r\n```csharp\r\nprotected override async Task AuthenticateAsync()\r\n{\r\n    if ( Principal == null || Properties == null )\r\n    {\r\n        await base.AuthenticateAsync();\r\n        if ( Principal == null ) return;\r\n        // Check that user can impersonate\r\n        var canImpersonate = Principal.GetFirstUserClaim( LogexClaimTypes.CanImpersonate );\r\n        if ( canImpersonate != \"true\" ) return; \r\n        var context = HttpContextAccessor.HttpContext;\r\n        // Check impersonation cookie\r\n        if ( !context.Request.Cookies.TryGetValue( CookieConstants.ImpersonateCookie, out var impersonatedUserLogin )\r\n             || string.IsNullOrWhiteSpace( impersonatedUserLogin ))\r\n        {\r\n            return;\r\n        }\r\n        // Get user to impersonate\r\n        var user = _userStore.FindByUsername( impersonatedUserLogin, false );\r\n        if ( user == null )\r\n        {\r\n            Logger.LogError( \"Impersonation user {login} is not found\", impersonatedUserLogin );\r\n            return;\r\n        }\r\n        var identity = Principal.Identities.First();\r\n        var claims = Principal.Claims\r\n            .Where( x => x.Type != JwtClaimTypes.Subject\r\n                      && x.Type != identity.NameClaimType )\r\n            .ToList();\r\n        claims.Add( new Claim( JwtClaimTypes.Subject, user.SubjectId ) );\r\n        claims.Add( new Claim( identity.NameClaimType, user.Username ) );\r\n        claims.Add( new Claim( LogexClaimTypes.Impersonator, Principal.GetSubjectId() ) );\r\n        var replacementIdentity = new ClaimsIdentity(\r\n            claims,\r\n            Principal.Identity.AuthenticationType,\r\n            identity.NameClaimType,\r\n            LogexClaimTypes.Role );\r\n        Principal = new ClaimsPrincipal( replacementIdentity );\r\n    }\r\n}\r\n```\r\n\r\nWorks fine (so far), but I need `AuthenticateAsync` method to be open for modifications.\r\n\r\n**Does this PR introduce a breaking change?**\r\nNo breaking changes.\r\n\r\n**Please check if the PR fulfills these requirements**\r\n- [x] The commit follows our [guidelines](https://github.com/IdentityServer/IdentityServer4/blob/dev/.github/CONTRIBUTING.md)\r\n- [ ] Unit Tests for the changes have been added (for bug fixes / features)\r\n\r\n**Other information**:\r\n","created_at":"2018-09-10T12:48:56Z","updated_at":"2018-09-10T12:48:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/2607/commits","review_comments_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/2607/comments","review_comment_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues/2607/comments","statuses_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/statuses/2a1d42570998675a2367ad7c41a2403214002d21","head":{"label":"AndrewMayorov:default-session-mod","ref":"default-session-mod","sha":"2a1d42570998675a2367ad7c41a2403214002d21","user":{"login":"AndrewMayorov","id":109781,"node_id":"MDQ6VXNlcjEwOTc4MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/109781?v=4","gravatar_id":"","url":"https://api.github.com/users/AndrewMayorov","html_url":"https://github.com/AndrewMayorov","followers_url":"https://api.github.com/users/AndrewMayorov/followers","following_url":"https://api.github.com/users/AndrewMayorov/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMayorov/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMayorov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMayorov/subscriptions","organizations_url":"https://api.github.com/users/AndrewMayorov/orgs","repos_url":"https://api.github.com/users/AndrewMayorov/repos","events_url":"https://api.github.com/users/AndrewMayorov/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMayorov/received_events","type":"User","site_admin":false},"repo":{"id":148153258,"node_id":"MDEwOlJlcG9zaXRvcnkxNDgxNTMyNTg=","name":"IdentityServer4","full_name":"AndrewMayorov/IdentityServer4","owner":{"login":"AndrewMayorov","id":109781,"node_id":"MDQ6VXNlcjEwOTc4MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/109781?v=4","gravatar_id":"","url":"https://api.github.com/users/AndrewMayorov","html_url":"https://github.com/AndrewMayorov","followers_url":"https://api.github.com/users/AndrewMayorov/followers","following_url":"https://api.github.com/users/AndrewMayorov/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMayorov/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMayorov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMayorov/subscriptions","organizations_url":"https://api.github.com/users/AndrewMayorov/orgs","repos_url":"https://api.github.com/users/AndrewMayorov/repos","events_url":"https://api.github.com/users/AndrewMayorov/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMayorov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AndrewMayorov/IdentityServer4","description":"OpenID Connect and OAuth 2.0 Framework for ASP.NET Core","fork":true,"url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4","forks_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/forks","keys_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/teams","hooks_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/hooks","issue_events_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/issues/events{/number}","events_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/events","assignees_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/assignees{/user}","branches_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/branches{/branch}","tags_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/tags","blobs_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/git/refs{/sha}","trees_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/statuses/{sha}","languages_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/languages","stargazers_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/stargazers","contributors_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/contributors","subscribers_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/subscribers","subscription_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/subscription","commits_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/commits{/sha}","git_commits_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/git/commits{/sha}","comments_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/comments{/number}","issue_comment_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/issues/comments{/number}","contents_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/contents/{+path}","compare_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/merges","archive_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/downloads","issues_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/issues{/number}","pulls_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/pulls{/number}","milestones_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/milestones{/number}","notifications_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/labels{/name}","releases_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/releases{/id}","deployments_url":"https://api.github.com/repos/AndrewMayorov/IdentityServer4/deployments","created_at":"2018-09-10T12:40:17Z","updated_at":"2018-09-10T12:40:21Z","pushed_at":"2018-09-10T12:40:38Z","git_url":"git://github.com/AndrewMayorov/IdentityServer4.git","ssh_url":"git@github.com:AndrewMayorov/IdentityServer4.git","clone_url":"https://github.com/AndrewMayorov/IdentityServer4.git","svn_url":"https://github.com/AndrewMayorov/IdentityServer4","homepage":"https://identityserver.io","size":9598,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"IdentityServer:dev","ref":"dev","sha":"8480e1d2b6770e6d0fc159d5a6444d9667dbf246","user":{"login":"IdentityServer","id":10635672,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNjM1Njcy","avatar_url":"https://avatars3.githubusercontent.com/u/10635672?v=4","gravatar_id":"","url":"https://api.github.com/users/IdentityServer","html_url":"https://github.com/IdentityServer","followers_url":"https://api.github.com/users/IdentityServer/followers","following_url":"https://api.github.com/users/IdentityServer/following{/other_user}","gists_url":"https://api.github.com/users/IdentityServer/gists{/gist_id}","starred_url":"https://api.github.com/users/IdentityServer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IdentityServer/subscriptions","organizations_url":"https://api.github.com/users/IdentityServer/orgs","repos_url":"https://api.github.com/users/IdentityServer/repos","events_url":"https://api.github.com/users/IdentityServer/events{/privacy}","received_events_url":"https://api.github.com/users/IdentityServer/received_events","type":"Organization","site_admin":false},"repo":{"id":46652227,"node_id":"MDEwOlJlcG9zaXRvcnk0NjY1MjIyNw==","name":"IdentityServer4","full_name":"IdentityServer/IdentityServer4","owner":{"login":"IdentityServer","id":10635672,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNjM1Njcy","avatar_url":"https://avatars3.githubusercontent.com/u/10635672?v=4","gravatar_id":"","url":"https://api.github.com/users/IdentityServer","html_url":"https://github.com/IdentityServer","followers_url":"https://api.github.com/users/IdentityServer/followers","following_url":"https://api.github.com/users/IdentityServer/following{/other_user}","gists_url":"https://api.github.com/users/IdentityServer/gists{/gist_id}","starred_url":"https://api.github.com/users/IdentityServer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IdentityServer/subscriptions","organizations_url":"https://api.github.com/users/IdentityServer/orgs","repos_url":"https://api.github.com/users/IdentityServer/repos","events_url":"https://api.github.com/users/IdentityServer/events{/privacy}","received_events_url":"https://api.github.com/users/IdentityServer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IdentityServer/IdentityServer4","description":"OpenID Connect and OAuth 2.0 Framework for ASP.NET Core","fork":false,"url":"https://api.github.com/repos/IdentityServer/IdentityServer4","forks_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/forks","keys_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/teams","hooks_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/hooks","issue_events_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues/events{/number}","events_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/events","assignees_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/assignees{/user}","branches_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/branches{/branch}","tags_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/tags","blobs_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/git/refs{/sha}","trees_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/statuses/{sha}","languages_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/languages","stargazers_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/stargazers","contributors_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/contributors","subscribers_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/subscribers","subscription_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/subscription","commits_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/commits{/sha}","git_commits_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/git/commits{/sha}","comments_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/comments{/number}","issue_comment_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues/comments{/number}","contents_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/contents/{+path}","compare_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/merges","archive_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/downloads","issues_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues{/number}","pulls_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls{/number}","milestones_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/milestones{/number}","notifications_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/labels{/name}","releases_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/releases{/id}","deployments_url":"https://api.github.com/repos/IdentityServer/IdentityServer4/deployments","created_at":"2015-11-22T08:21:58Z","updated_at":"2018-09-10T12:25:56Z","pushed_at":"2018-09-10T12:09:36Z","git_url":"git://github.com/IdentityServer/IdentityServer4.git","ssh_url":"git@github.com:IdentityServer/IdentityServer4.git","clone_url":"https://github.com/IdentityServer/IdentityServer4.git","svn_url":"https://github.com/IdentityServer/IdentityServer4","homepage":"https://identityserver.io","size":9598,"stargazers_count":3294,"watchers_count":3294,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":941,"mirror_url":null,"archived":false,"open_issues_count":102,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":941,"open_issues":102,"watchers":3294,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/2607"},"html":{"href":"https://github.com/IdentityServer/IdentityServer4/pull/2607"},"issue":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues/2607"},"comments":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/issues/2607/comments"},"review_comments":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/2607/comments"},"review_comment":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/pulls/2607/commits"},"statuses":{"href":"https://api.github.com/repos/IdentityServer/IdentityServer4/statuses/2a1d42570998675a2367ad7c41a2403214002d21"}},"author_association":"NONE","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":1,"additions":4,"deletions":4,"changed_files":1}}
{"actor":{"display_login":"AndrewMayorov"}}