{"action":"created","issue":{"url":"https://api.github.com/repos/IdentityServer/IdentityServer3/issues/1799","labels_url":"https://api.github.com/repos/IdentityServer/IdentityServer3/issues/1799/labels{/name}","comments_url":"https://api.github.com/repos/IdentityServer/IdentityServer3/issues/1799/comments","events_url":"https://api.github.com/repos/IdentityServer/IdentityServer3/issues/1799/events","html_url":"https://github.com/IdentityServer/IdentityServer3/issues/1799","id":103754916,"number":1799,"title":"Dynamically Add Claims to User During Authentication","user":{"login":"iltera","id":6315109,"avatar_url":"https://avatars.githubusercontent.com/u/6315109?v=3","gravatar_id":"","url":"https://api.github.com/users/iltera","html_url":"https://github.com/iltera","followers_url":"https://api.github.com/users/iltera/followers","following_url":"https://api.github.com/users/iltera/following{/other_user}","gists_url":"https://api.github.com/users/iltera/gists{/gist_id}","starred_url":"https://api.github.com/users/iltera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iltera/subscriptions","organizations_url":"https://api.github.com/users/iltera/orgs","repos_url":"https://api.github.com/users/iltera/repos","events_url":"https://api.github.com/users/iltera/events{/privacy}","received_events_url":"https://api.github.com/users/iltera/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-28T16:52:45Z","updated_at":"2015-10-07T14:12:25Z","closed_at":"2015-09-01T07:23:42Z","body":"I want to add some claims ON THE FLY, without writing any records in the database. I am using implicit flow on AngularJS client app and WebApi with BearerTokenAuthentication setup.\r\n\r\nMy implementation of GetProfileDataAsync is like this:\r\n\r\n    public override Task GetProfileDataAsync(ProfileDataRequestContext context)\r\n    {\r\n        var user = db.Users.SingleOrDefault(x => x.UserName == context.Subject.Identity.Name);\r\n\r\n        if (user != null)\r\n        {\r\n            var identity = new ClaimsIdentity();\r\n            identity.AddClaims(new[]\r\n            {\r\n                new Claim(\"preferred_username\", user.UserName),\r\n                new Claim(\"email\", user.Email)\r\n            });\r\n\r\n            if (context.RequestedClaimTypes != null)\r\n            {\r\n                var result = identity.Claims.Where(x => context.RequestedClaimTypes.Contains(x.Type));\r\n                return Task.FromResult(result);\r\n            }\r\n\r\n            return Task.FromResult(identity.Claims);\r\n        }\r\n\r\n        return Task.FromResult<IEnumerable<Claim>>(null);\r\n    }\r\n\r\nI have\r\n\r\nIncludeAllClaimsForUser = true (in Scopes table)\r\nAlwaysIncludeInIdToken = true (for every scope claim for these scopes in ScopeClaims table)\r\nAlwaysSendClientClaims = true (in Clients table)\r\n\r\nWith this setup I no longer get any of these requested values in OIDCTokenManager's profile attribute. When I comment this method, I have them all.\r\n\r\nWhat is wrong with my approach?"},"comment":{"url":"https://api.github.com/repos/IdentityServer/IdentityServer3/issues/comments/146206846","html_url":"https://github.com/IdentityServer/IdentityServer3/issues/1799#issuecomment-146206846","issue_url":"https://api.github.com/repos/IdentityServer/IdentityServer3/issues/1799","id":146206846,"user":{"login":"benjaminadrom","id":15014100,"avatar_url":"https://avatars.githubusercontent.com/u/15014100?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaminadrom","html_url":"https://github.com/benjaminadrom","followers_url":"https://api.github.com/users/benjaminadrom/followers","following_url":"https://api.github.com/users/benjaminadrom/following{/other_user}","gists_url":"https://api.github.com/users/benjaminadrom/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaminadrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaminadrom/subscriptions","organizations_url":"https://api.github.com/users/benjaminadrom/orgs","repos_url":"https://api.github.com/users/benjaminadrom/repos","events_url":"https://api.github.com/users/benjaminadrom/events{/privacy}","received_events_url":"https://api.github.com/users/benjaminadrom/received_events","type":"User","site_admin":false},"created_at":"2015-10-07T14:12:25Z","updated_at":"2015-10-07T14:12:25Z","body":"before \"return Task\" \r\nadd claims to \"context.IssuedClaims\" like this:\r\ncontext.IssuedClaims = identity.Claims; "}}