You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spoke to soon regarding my success. The following code works for a site, but after the initial success other items on the page may also return 401 wanting to reauthorize and this seems to fail. Also seems to effect other pages. Wanted to know if you had any ideas on why images or other items on a page hosted in the same location might do this.
I can't access the stream with Titanium like you do in your examples or in the benderproxy.
I may also just not understand NTLM enough. After the passing of type 3 do I need to pass it again with every 401 reply?
private async Task OnResponse(object sender, SessionEventArgs e)
{
// Only do any processing on the response if the response is 401,
if (e.HttpClient.Response.StatusCode == 401)
{
var authHeaders = e.HttpClient.Response.Headers.Where(h => h.Name.IndexOf("WWW-Authenticate", StringComparison.InvariantCultureIgnoreCase) >= 0);
ISeleniumProxyAuth auth = Settings.Proxy.Auth.FirstOrDefault(a =>
a.Hosts.Any(h => h.IsMatch(e.HttpClient.Request.Host))
&& authHeaders.Any(header => header.Value.StartsWith(a.Type.ToString())));
switch (auth?.Type)
{
case AuthType.Basic:
{
var basicAuthHeaderValue = $"{auth.User}:{auth.Pass}";
var encodedHeaderValue = Convert.ToBase64String(Encoding.ASCII.GetBytes(basicAuthHeaderValue));
e.HttpClient.Request.Headers.AddHeader("Authorization", "Basic " + encodedHeaderValue);
e.ReRequest = true;
break;
}
case AuthType.NTLM:
{
HttpHeader header = authHeaders.FirstOrDefault(x =>
x.Value.StartsWith(NtlmGenerator.AuthorizationHeaderMarker));
if (header?.Value == NtlmGenerator.AuthorizationHeaderMarker)
{
var type1 = new NtlmNegotiateMessageGenerator();
var type1HeaderValue = type1.GenerateAuthorizationHeader();
e.HttpClient.Request.Headers.AddHeader("Authorization", type1HeaderValue);
e.ReRequest = true;
}
else
{
var type2 = new NtlmChallengeMessageGenerator(header?.Value);
var type3 = new NtlmAuthenticateMessageGenerator(null, null, auth.User, auth.Pass, type2);
var type3HeaderValue = type3.GenerateAuthorizationHeader();
e.HttpClient.Request.Headers.RemoveHeader("Authorization");
e.HttpClient.Request.Headers.AddHeader("Authorization", type3HeaderValue);
e.ReRequest = true;
}
break;
}
}
}
}
The text was updated successfully, but these errors were encountered:
I spoke to soon regarding my success. The following code works for a site, but after the initial success other items on the page may also return 401 wanting to reauthorize and this seems to fail. Also seems to effect other pages. Wanted to know if you had any ideas on why images or other items on a page hosted in the same location might do this.
I can't access the stream with Titanium like you do in your examples or in the benderproxy.
I may also just not understand NTLM enough. After the passing of type 3 do I need to pass it again with every 401 reply?
The text was updated successfully, but these errors were encountered: