Beispiel #1
0
        public async Task Invoke(HttpContext context)
        {
            //获取cookie中的token
            string token;

            context.Request.Cookies.TryGetValue("Token", out token);

            //如果没有token,肯定是不成功的
            if (string.IsNullOrWhiteSpace(token))
            {
                RedirectLoginSite(context);

                return;
            }

            //校验token是否有效
            HttpRequester requester = new HttpRequester(_configuration);

            context.Request.Headers.TryAdd("Token", token);

            var response = await requester.GetResponse("Auth_Validate", context.Request);

            if (response.Data != null && response.Data.IsSuccessStatusCode)
            {
                await _next.Invoke(context);
            }
            else
            {
                RedirectLoginSite(context);
            }
        }