private void SetCurrentApiKeyPrincipal(HttpContext context, ExternalService service) { var identity = new PanelUserIdentity() { IsAuthenticated = true, UserId = service.Id.ToString() }; context.User = new ClaimsPrincipal(identity); ((ClaimsIdentity)context.User.Identity).AddClaim(new Claim("UserId", service.Id.ToString())); }
private void SetCurrentPrincipal(AuthorizationFilterContext context) { if (context.HttpContext.User.Identity.IsAuthenticated && context.HttpContext.User.Identity.AuthenticationType == "JWT") { var identity = (ClaimsIdentity)context.HttpContext.User.Identity; var panelIdentity = new PanelUserIdentity() { IsAuthenticated = identity.IsAuthenticated, UserId = identity.Claims.FirstOrDefault(x => x.Type == "UserId").Value }; Thread.CurrentPrincipal = new PanelUserPrincipal(panelIdentity); return; } var principal = new PanelUserPrincipal( new PanelUserIdentity() { IsAuthenticated = true, UserId = context.HttpContext.User.Claims.FirstOrDefault(x => x.Type == "UserId")?.Value, }); Thread.CurrentPrincipal = principal; }
public PanelUserPrincipal(PanelUserIdentity panelUserIdentity) { _panelUserIdentity = panelUserIdentity; }