public async Task Invoke(HttpContext context, IAuthenticationService authenticationService)
        {
            try
            {
                var parser = new BasicAuthenticationParser(context);
                var username = parser.GetUsername();
                var password = parser.GetPassword();

                await authenticationService.AuthenticateAsync(username, password);
                await next(context);
            }
            catch (InvalidCredentialsException)
            {
                context.Response.StatusCode = 401;
                context.Response.Headers.Add("WWW-Authenticate", new[] { "Basic" });
            }
        }
Exemple #2
0
        public async Task Invoke(HttpContext context, IAuthenticationService authenticationService)
        {
            try
            {
                var parser   = new BasicAuthenticationParser(context);
                var username = parser.GetUsername();
                var password = parser.GetPassword();

                await authenticationService.AuthenticateAsync(username, password);
                await next(context);
            }
            catch (InvalidCredentialsException)
            {
                context.Response.StatusCode = 401;
                context.Response.Headers.Add("WWW-Authenticate", new[] { "Basic" });
            }
        }