Hello,
I am facing an issue involving using URLSession to make API requests through an authenticated proxy.
This was originally observed on 10.12.6, but I have also reproduced it on 10.13.3.
I have written a very simple test program to demonstrate:
let url = URL(string: "https://api.myjson.com/bins/vi56v")
let task = URLSession.shared.dataTask(with: url!) {(data, response, error ) in
guard error == nil else {
print("returned error")
return
}
guard let content = data else {
print("No data")
return
}
print("Got data: \(String.init(data: content, encoding: .utf8) ?? "decode failure")")
}
task.resume()
RunLoop.main.run()Running this without any proxy configured produces the correct result, which lists several Silicon Valley tech companies in JSON form.
Once I configure an autheticated HTTP/HTTPS proxy in System Preferences, however, it stops working. The request fails and the non-specific "Failed to get applicable proxy auth" is printed in the Console. Of interest, the username and password for this proxy are properly configured and present in the keychain, but the app does not seem to even be attemping to read them, because no keychain authorization prompts are seen.
What is of further interest is that this appears to be related to the authentication methods offered by the proxy. The inital 407 rejection contains numerous authentication options (XXXXXXX added to obscure private information):
HTTP/1.1 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )
Via: 1.1 XXXXXXX
Proxy-Authenticate: Negotiate
Proxy-Authenticate: Kerberos
Proxy-Authenticate: NTLM
Proxy-Authenticate: Basic realm="XXXXXXXX"
Connection: close
Proxy-Connection: close
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 712 However, if I modify the response (using networking tricks) to remove the Kerberos and Negotiate lines, all of a sudden everything starts working great. Keychain access is requested, and I see a proper NTLM 3-way handshake. Since our major requirement is to support NTLM, this is good.
Unfortunately, I think telling our customers "whatever you do, don't enable Kerberos on your proxy" is not going to cut it. I've looked around left and right for some way to override the authentication process for proxies, but all answers (including those from this forum) indicate that "it's magic, there's no way to customize it".
Any ideas on how to proceed?