netcore2-reverse-proxy icon indicating copy to clipboard operation
netcore2-reverse-proxy copied to clipboard

windows authentication

Open dragouf opened this issue 4 years ago • 1 comments

great example. Just a not, in a windows authentication (NTLM) network, just do that :

private static readonly HttpClient _httpClient = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true });

to transfer authentication with the request.

dragouf avatar Nov 13 '20 13:11 dragouf

also, since it will be windows auth of the server in this case you can transfer browser windows user by using impersonation like this :

var wi = (WindowsIdentity)context.User.Identity;
// transfer windows user of the browser request (impersonate)
await WindowsIdentity.RunImpersonatedAsync(wi.AccessToken, async () =>
{
    using (var responseMessage = await _httpClient.SendAsync(targetRequestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted))
     {
         context.Response.StatusCode = (int)responseMessage.StatusCode;

        this.CopyFromTargetResponseHeaders(context, responseMessage);

         await this.ProcessResponseContent(context, responseMessage);
    }
});

dragouf avatar Nov 20 '20 13:11 dragouf