vlaci / openconnect-sso

Wrapper script for OpenConnect supporting Azure AD (SAMLv2) authentication to Cisco SSL-VPNs
GNU General Public License v3.0
299 stars 131 forks source link

config address from server arguments instead of redirect #94

Closed JohnRigoni closed 2 years ago

JohnRigoni commented 2 years ago

Problem: The VPN address I am connecting to is a load balancer and will redirect me to a subdomain. This subdomain is then saved in the 'address' field of the profile in the config file. When connecting again, this address is used by default to make the connection and results in the user directly connecting to the subdomain rather than load balancer/original URL. This is due to the configuration file being saved only after the target URL is redirected. After loading/generating the HostProfile object, it is copied to cfg.default_profile. But then, the HostProfile object will have its URL changed by _detect_authentication_target_url() (to be used later for connecting to open-connect and logging). No other aspects of the HostProfile object change after initialization.

Solution: Set cfg.default_profile to the HostProfile object named selected_profile. Then the selected_profile object will be used to generate an identical HostProfile object called working_profile. This working_profile object will be returned after its 'address' field is resolved so anything using the resolved URL is not impacted. Essentially the config that gets saved will maintain the original address that the user submitted when initially connecting to the server, rather than what _detect_authentication_target_url() redirects to. Avoids re-configuring the config file and does not require any significant changes. Do not need to import a library like copy.

This is my first pull request so please let me know if there is anything I have misconstrued. I realize it is not the best solution but was the best I could figure without significant changes.