-
Notifications
You must be signed in to change notification settings - Fork 101
Description
I am working on building an integration between two environments and will be making a lot of HttpClient Posts to a legacy IIS site internal in our network that is running windows authentication. In testing below is a sample of my code I used to test getting a Kerberos ticket and attaching it to my HttpClient as an Auth header. this works. I am working from a linux container not running in our domian so I need to set authentication into my HttpClient to authenticate into the site.
var apiHost = "http://[internal web server]";
Guard.Against.NullOrEmpty(apiHost);
var hostUri = new Uri(apiHost);
using var client= ClientFactory.CreateClient("[Facotry client name]");
client.BaseAddress = hostUri;
DnsQuery.RegisterImplementation(new PlatformIndependentDnsClient());
using var kClient = new KerberosClient();
var kerbCred = new KerberosPasswordCredential("[Account]", "[Password]", "[]Domain");
await kClient.Authenticate(kerbCred);
var ticket = await kClient.GetServiceTicket($"http/{hostUri.Host}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Negotiate", Convert.ToBase64String(ticket.EncodeGssApi().ToArray()));
var apiPath= "[Path to App]";
string inputJson = Newtonsoft.Json.JsonConvert.SerializeObject(GetEvent());
HttpContent inputContent = new StringContent(inputJson, System.Text.Encoding.UTF8, "application/json");
var apiResponse = await client.PostAsync(apiPath, inputContent);
apiResponse.EnsureSuccessStatusCode();
I am wonder if there are some ideas to make it perform with high volume of calls coming through? Is there a cache I should use? Do I make singleton to provide the token and only refresh it as needed? I guess any ideas you have to use this logic in a high volume (using the same account ) environment would be greatly appreciated.