connect method

Future<void> connect({
  1. required String serverUrl,
  2. required String name,
  3. String? username,
  4. String? password,
  5. String? certPath,
  6. String? certPassword,
  7. String? caPath,
  8. String? authGroup,
  9. String? servercert,
  10. OCAuthMethod authMethod = OCAuthMethod.password,
  11. List<String>? bypassPackages,
})

Connect to an OpenConnect / ocserv gateway.

serverUrl – HTTPS URL of the VPN gateway (e.g. https://vpn.host.com). username – User account for password or TOTP auth. password – Password or TOTP code. certPath – Path to a PEM/P12 client certificate (certificate auth). certPassword– Passphrase for an encrypted client certificate. caPath – Custom CA certificate path to trust. Supply for self-signed servers. authGroup – Optional group/realm name required by some gateways. servercert – SHA1 fingerprint of the server cert to pin (e.g. sha1:<hex>). Set to pin-sha256:<b64> for SHA-256 pinning. name – Display name shown in system VPN notification. authMethod – Hint to the native layer about the auth flow. bypassPackages – Android only: apps to exclude from the tunnel.

Implementation

Future<void> connect({
  required String serverUrl,
  required String name,
  String? username,
  String? password,
  String? certPath,
  String? certPassword,
  String? caPath,
  String? authGroup,
  String? servercert,
  OCAuthMethod authMethod = OCAuthMethod.password,
  List<String>? bypassPackages,
}) async {
  if (!initialized) {
    throw StateError('OpenConnect must be initialized first.');
  }

  _tempDateTime = DateTime.now();

  try {
    await _channelControl.invokeMethod('connect', {
      'server_url': serverUrl,
      'name': name,
      'username': username,
      'password': password,
      'cert_path': certPath,
      'cert_password': certPassword,
      'ca_path': caPath,
      'auth_group': authGroup,
      'servercert': servercert,
      'auth_method': authMethod.name,
      'bypass_packages': bypassPackages ?? [],
    });
  } on PlatformException catch (e) {
    throw ArgumentError(e.message);
  }
}