NSURLSession: how to program proxy username password?

Hello;

i try to use the native calls to execute soap calls : NSURL, dataTaskWithRequest, ...
This works well when having direct access to the internet, as well as connecting via proxy server.
Session and Task specific challenge handlers didReceiveChallenge are implemented.
All fails however when System Preferences are configured for proxy server requiring authentication.
In this configuration, there is a popup panel (provided by macOS?) "Proxy Authentication Required" - Not Now' - "System Preferences".

1.
When clicking "Not Now" button, there is a console message " mach_port_deallocate (os/kern) invalid right"

followed by task specific challenge call NSURLAuthenticationMethodHTTPBasic


2.

When clicking on System Preferences button, there is Username, Password panel

Also in the console there is a message

*** WARNING: CFMachPortSetInvalidationCallBack() called on a CFMachPort with a Mach port (0x11503) which does not have any send rights. This is not going to work. Callback function: 0x7fff4ad86744

When entering the proxy credentials, there is again a console message "....mach_port_deallocate .. invalid right".
But no handlers didReceiveChallenge is called.

How can i establish the handler didReceiveChallenge to be called (is not called now!)
and can i use the macos? provided credential panel info (username password)?
to be send along to completionhandler.

The various log messages you noticed are just log noise.

The fact that the system’s built in proxy UI tries to handle proxy authentication before your app’s authentication challenge handlers are called is a bug (r. 21847695) [1]. This is particularly annoying in the case where you’re configuring a custom proxy (

connectionProxyDictionary
), but that doesn’t appear to be the case in your tests. If you’re not customising the proxy settings, you should leave it to the system to handle proxy authentication challenges. You might be able to make some progress on your own but, realistically, if the system isn’t handling proxy authentication challenges, all sorts of other things are going to break.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

ps DTS is closed 21 Dec through 1 Jan.

[1] One that’s hard to fix given the current

NSURLSession
architecture and the compatibility constraints imposed by the current authentication challenge API (r. 30417163).
NSURLSession: how to program proxy username password?
 
 
Q