public override void OnAuthorization(HttpActionContext actionContext) { if (actionContext.Request.Headers.Contains(Constants.AuthenticationHeaderName)) { var maybeApiKey = actionContext.Request.Headers.GetValues(Constants.AuthenticationHeaderName).ToList(); if (maybeApiKey.Count() != 1) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); } else { if (!_apiKeyRepository.IsValid(maybeApiKey.First())) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden); } } } else { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); } }