public async Task InvokeAsync(HttpContext context) { if (_sessionService.Any(SessionKey.CURRENT_USER)) { var currentUser = _sessionService.GetObject <User>(SessionKey.CURRENT_USER); // TODO: Claim call operations will be taken to the Business layer later. var claimsResult = _userManager.GetClaimsByUserId(currentUser.Id); if (claimsResult.IsSuccess && claimsResult.Data != null) { var claims = new List <Claim>(); foreach (var claim in claimsResult.Data) { claims.AddRole(claim.Name); } var claimsIdentity = new ClaimsIdentity(claims); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity); context.User = claimsPrincipal; } } await _next(context); }
public void OnActionExecuting(ActionExecutingContext context) { //var any = context // .ActionDescriptor // .EndpointMetadata.Select(i => i.GetType().FullName == typeof(SkipCheckSessionFilter).FullName).Any(); //if (any) //{ // return; //} _sessionService = context.HttpContext.RequestServices.GetService <ISessionService>(); var isUserLoggedIn = _sessionService.Any(SessionKey.CURRENT_USER); if (!isUserLoggedIn) { context.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Login" } }); } }