public void OnActionExecuting(ActionExecutingContext context) { var authAttribute = context .ActionDescriptor .FilterDescriptors .Select(x => x.Filter) .OfType <AuthAttribute>() .FirstOrDefault(); if (authAttribute == null) { return; } var task = _authService.Authenticate(new AuthenticatorRequest() { Path = authAttribute.Path, Service = _options, Subject = GetSubject(context.HttpContext.User) }); task.Wait(); var result = task.Result; if (!result.IsAuthenticated) { context.Result = new StatusCodeResult(401); return; } if (result.IsAuthenticated && !result.IsAuthorized) { context.Result = new StatusCodeResult(403); return; } UpdateClaims(result, context); }
public async Task <AuthenticatorResponse> Post([FromBody] AuthenticatorRequest request) { return(await _authenticatorService.Authenticate(request)); }