public async Task Invoke(HttpContext context)
        {
            var token = context.Request.Headers["Authorization"].ToString();

            if (token != "")
            {
                var ClaimsPrincipal = _provider.Validate(token);
                context.User = ClaimsPrincipal;
            }

            await _next(context);

            return;
        }
Пример #2
0
        public async Task Invoke(HttpContext context)
        {
            if (!context.Request.Path.Value.Contains("api"))
            {
                await _next(context);

                return;
            }

            else if (context.Request.Path.Value.Contains("login"))
            {
                await _next(context);

                return;
            }

            else if (!context.Request.Headers.ContainsKey("Authorization"))
            {
                context.Response.StatusCode = 403;
                return;
            }

            else if (!context.Request.Headers["Authorization"].ToString().Contains("Bearer "))
            {
                context.Response.StatusCode = 403;
                return;
            }

            var Token = context.Request.Headers["Authorization"].ToString().Split(new char[] { ' ' })[1];

            try
            {
                var ClaimsPrincipal = _provider.Validate(Token);
                context.User = ClaimsPrincipal;
            }
            catch (Exception ex)
            {
                context.Response.StatusCode = 403;
                return;
            }


            await _next(context);

            return;
        }