(reply to an old question but might be useful to others)
I had a similar problem where we needed to put a facade in front of a web api that only supports basic or kerberos authentication.
I used this solution that transforms the incoming url to the url of the backend server: http://www.dotnetspeak.com/asp-net-mvc/using-webapi-in-multi-tier-web-application/
I added some logic to that solution to check the token (from the asp.net login system) in the header because ExecuteAsync executes before the Authorization filters:
var token = controllerContext.Request.Headers.Authorization;
if (token != null && token.Scheme.Equals("bearer", StringComparison.InvariantCultureIgnoreCase))
{
var ticket = Startup.OAuthOptions.AccessTokenFormat.Unprotect(token.Parameter);
if (ticket != null && ticket.Identity != null && ticket.Identity.IsAuthenticated)
{
var claimsPrincipal = new ClaimsPrincipal(ticket.Identity);
//From here, you can use the claimsPrinciple to check if user is allowed to even call the service.
var authorized = claimsPrincipal.IsInRole("Users");
}
}
if Startup.OAuthOptions is not available, you might need to convert this to a static variable in Startup.cs or Startup.Auth.cs.
Because I needed to provide an alternative authentication method instead of the basic authentication of the backend service, an additional updating of the header is added to switch to basic Auth.
//from the dotnetspeak solution (copy existing headers)
foreach (var httpRequestHeader in controllerContext.Request.Headers)
{
client.DefaultRequestHeaders.Add(httpRequestHeader.Key, httpRequestHeader.Value);
}
//Set basic authentication, whatever the original Authorization header might have been
//TODO: use lookup table or something like that to convert claimsPrinciple to matching domain user account
var byteArray = Encoding.ASCII.GetBytes(@"Domain\userId:password");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));