I followed http://bitoftech.net/2014/12/15/secure-asp-net-web-api-using-api-key-authentication-hmac-authentication/ to do a custom authentication filter.
Everything is working correctly but I cannot get the server to say anything upon a 401. It correctly gives the www-authenicate
header and status code 401 but no content/body.
I tried using AuthenticationFailureResult
the from http://www.asp.net/web-api/overview/security/authentication-filters but did not help. I converted my AuthenticateAsync
to async
and ignored the await
warning.
This is my current work around, the code in comments is what I -wish- I could do, that is mostly have it use whatever formatter
//request.CreateResponse(HttpStatusCode.Unauthorized, new { Error = true, Message = "Token is invalid" });
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.Write("{ \"Error\" = true, \"Message\" = \"Token is invalid\" }");
context.ErrorResult = new UnauthorizedResult(new AuthenticationHeaderValue[0], request);