Search code examples
objective-ccocoansurlconnectionnsurlconnectiondelegate

Why am i getting the proxy authentication dialogue from mac when i have implemented the didReceiveAuthenticationChallenge method?


Is there any way i can suppress this implicit authentication dialogue ?

I am getting this dialogue before my didRecieveAuthenticationChallenge function is being called. What I am not able to understand is why this dialogue is in place if i have handling authentication on my own.

I am returning YES from canAuthenticateAgainstProtectionSpace method. But the dialogue appears prior to hit that


Solution

  • OS X and iOS call your app's handler only for challenges that provide a WWW-Authenticate header. Typically, a proxy challenge provides a 407 response with a Proxy-Authenticate header, which is not treated as a challenge that an app can respond to.

    If you know the credentials for the proxy somehow, you can pre-populate the user's keychain with those credentials, and the OS will automatically use them.

    If you're in control over the proxy, you can make it send a 401, and the OS will pass that through to your client. Alternatively, in iOS 9 and OS X v10.11, you might be able to take advantage of the network extension stuff to control the proxy, but that is generally only appropriate if the purpose of your app is to control some hardware that acts as a proxy, and I haven't looked at those aspects of NE to know whether it even provides that level of control.

    Otherwise, the OS is behaving as expected, and there's not much you can do about it other than to file a bug asking for a new authentication challenge type for proxy authentication.