For basic authentication, just set the ProxyBasicAuthenticateFunc
property on the ProxyServer
instance. For example:
void Main()
{
var proxyServer = new ProxyServer();
proxyServer.OnClientConnectionCreate += OnConnect;
proxyServer.BeforeRequest += OnBeforeRequest;
var socksProxy = new SocksProxyEndPoint(IPAddress.Loopback, 1080, false);
proxyServer.ProxyBasicAuthenticateFunc = OnBasicAuth;
proxyServer.AddEndPoint(socksProxy);
proxyServer.Start();
...
}
public Task<bool> OnBasicAuth(SessionEventArgsBase ev, string u, string p) {
if (u == "test" && p == "pass") {
return Task.FromResult(true);
}
return Task.FromResult(false);
}
Note that the data will be sent in plain text (no encryption). It could be acceptable in intranets, but if you allow public access to your proxy, either use a different authentication scheme (ProxySchemeAuthenticateFunc) or tunnel the traffic.