public async Task Connect(VPNConnection conn) { VpnManagementAgent mgr = new VpnManagementAgent(); VpnNativeProfile profile = new VpnNativeProfile() { AlwaysOn = true, NativeProtocolType = VpnNativeProtocolType.Pptp, ProfileName = conn.ConnectionName, RememberCredentials = true, RequireVpnClientAppUI = false, RoutingPolicyType = VpnRoutingPolicyType.ForceAllTrafficOverVpn, TunnelAuthenticationMethod = VpnAuthenticationMethod.PresharedKey, UserAuthenticationMethod = VpnAuthenticationMethod.PresharedKey }; profile.Servers.Add(conn.ServerName); VpnManagementErrorStatus profileStatus = await mgr.AddProfileFromObjectAsync(profile); PasswordCredential credentials = new PasswordCredential { UserName = conn.UserName, Password = conn.Password, }; VpnManagementErrorStatus connectStatus = await mgr.ConnectProfileWithPasswordCredentialAsync(profile, credentials); activeProfile = profile; }
public async Task DoConnect(Config.Server server) { profile.Servers.Add(server.serverAddress); VpnManagementErrorStatus status = await manager.AddProfileFromObjectAsync(profile); if (status != VpnManagementErrorStatus.Ok) { throw new Exception("VPN profile add failed. Status is " + status); } PasswordCredential credentials = new PasswordCredential { UserName = server.eap_name, Password = server.eap_secret, }; status = await manager.ConnectProfileWithPasswordCredentialAsync(profile, credentials); if (status != VpnManagementErrorStatus.Ok) { throw new Exception("VPN profile delete failed. Status is " + status); } }