I am new to web development using Web API and I'm having some issues dealing with authentication using a custom message handler - specifically calling the Web API methods from a C# WPF application using HttpClient.
I've implemented authentication using a custom DelegatingHandler as in the TokenInspector class example given here (minus the HTTPS stuff). From the post I understand this moves authentication higher up in the request pipeline than having Action Filters as in this popular post.
I can successfully call my secured methods using an ajax call like the following (where _key is the security token):
$.ajax({
url: _api + '/Item',
beforeSend: function(request) {
request.setRequestHeader("X-Token", _key);
},
type: 'GET',
dataType: 'json',
success: fnSuccessResult,
error: function (xhr, status, error) {
alert(xhr.status + ' ' + status + ' ' + error);
}
});
I am in the process of writing a test harness for my Web API in C# - how do I handle this type of authentication in C# using HttpClient?