public async Task InvokeAsync(HttpContext context, ITokenValidator tokenValidator)

        {
            if (!context.Request.Cookies.ContainsKey("Token"))
            {
                await _next.Invoke(context);
            }

            else
            {
                if (!context.Request.Cookies.TryGetValue("Token", out var token) || string.IsNullOrWhiteSpace(token))
                {
                    context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    throw new UnauthorizedAccessException("Unauthorized");
                }
                if (tokenValidator.ValidateAndExtract(context, token))
                {
                    await _next.Invoke(context);
                }
                else
                {
                    throw new UnauthorizedAccessException("Unauthorized");
                }
            }
        }
        public async Task Invoke(HttpContext context, IUserManagerAuthentication authenticationManager, ITokenValidator tokenValidator)
        {
            var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();

            if (!string.IsNullOrWhiteSpace(token))
            {
                await tokenValidator.ValidateAndExtract(context, authenticationManager, token);
            }
            await _next(context);
        }