I have written a custom DelegatingHandler
that intercepts requests and authenticates it against an API key. This was being used in a WebApi service, pre ASP.NET 5.
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var apiKey = string.Empty; //ConfigurationManager.AppSettings.Get("apiKey");
if (request.Headers.GetValues("Auth").FirstOrDefault() == apiKey)
return base.SendAsync(request, cancellationToken);
var error = new HttpError("Unauthorized.");
var response = request.CreateErrorResponse(HttpStatusCode.Unauthorized, error);
return Task.FromResult(response);
}
I need to be able to use this same handler in a new ASP.NET 5 WebApi service. Will these types of handlers still work or do I have to rewrite it to fit the new framework? If not, how on Earth do I reference it?