I'm trying to change the system proxy settings with authentication. The system proxy can be changed successfully, but when my App relaunched, the auhorizating dialog(requiring username and password) always pop up.
How can I authorize once and for all?
I have a demo App with source codes on GitHub: "https://github.com/codinn/SystemProxySettingsDemo"
details:
Demo App description
A demo for changing system proxy settings.
Problem
After click “Enable System Proxy”, a dialog for requesting auhorization will be popped up, and subsequent clicks won't popup again, which is fine.
But if we Quit and Relaunch the app, the auhorizating dialog will be popped up again.
How can we authorize once and for all?
Steps to Reproduce
1. Launch demo app “SystemProxySettingsDemo”
2. Click “Enable System Proxy” button, the auhorizating dialog will be popped up
3. The SOCKS proxy setting in system network preferences will be changed to host: 127.0.0.1, port: 8888
4. Click “Disable System Proxy” button to clear system network preferences proxy
5. Quit the app, and launch it again
6. Click “Enable System Proxy” button, the auhorizating dialog will be popped up, again
References
1. GitHub repository: "https://github.com/codinn/SystemProxySettingsDemo"
2. Apple official sample: "https://developer.apple.com/library/content/samplecode/EvenBetterAuthorizationSample/Introduction/Intro.html"
3. File “ViewController.swift”: Creating an authorization reference, Requesting Authorization, System Network Preferences Proxy settings.
function define:
// requesting authorization with “AuthorizationCopyRights”
// set system network preferences proxy with “SCPreferencesCreateWithAuthorization” and “SCPreferencesPathSetValue”
func socksProxySet(enabled: Bool)4. File “CommonAuthorization.swift”: set / get authorization policy database entries
5. File “codinnDemoRightRemove.sh”: clear policy database entries belongs to demo app
Other Notes:
1. I've tried storing the Authorization Rights to the policy database with “AuthorizationRightSet” (setting policy database rule attribute “timeout” as 0, or 3600, or remove the attribute “timeout”), but it does not work
2. Also tried using "kAuthorizationRuleClassAllow" or "kAuthorizationRuleAuthenticateAsAdmin" as value for parameter "rightDefinition" of function "AuthorizationRightSet", but it does not work either