authenticate static method

Future<Uri?> authenticate(
  1. String url, {
  2. required String callbackScheme,
  3. bool ephemeral = false,
  4. Duration timeout = const Duration(minutes: 5),
})

Opens url for sign-in and returns the redirect back to callbackScheme (or null if cancelled).

Implementation

static Future<Uri?> authenticate(String url, {required String callbackScheme, bool ephemeral = false, Duration timeout = const Duration(minutes: 5)}) async {
  if (kIsWeb) return ULaunchWeb.authenticate(url, callbackScheme, timeout);
  if (Platform.isIOS || Platform.isMacOS) {
    final String? result = await _call<String>("authenticate", <String, Object?>{"url": url, "scheme": callbackScheme, "ephemeral": ephemeral});
    return result == null ? null : Uri.tryParse(result);
  }
  if ((Platform.isWindows || Platform.isLinux) && callbackScheme.startsWith("http://localhost")) return _loopback(url, Uri.parse(callbackScheme), timeout);
  // Android and desktop custom schemes: wait for the redirect to come back as a deep link.
  _listen();
  final Future<Uri?> redirect = _links.stream.firstWhere((Uri u) => u.scheme == callbackScheme).then<Uri?>((Uri u) => u).timeout(timeout, onTimeout: () => null);
  if (!await open(url, mode: Platform.isAndroid ? ULaunchMode.inApp : ULaunchMode.external)) return null;
  final Uri? result = await redirect;
  unawaited(closeInApp());
  return result;
}