start method
Binds the loopback server and returns the redirect URI.
Implementation
Future<String> start({
Duration timeout = const Duration(minutes: 5),
String callbackHost = '127.0.0.1',
}) async {
this.callbackHost = callbackHost;
await close();
_result = Completer<AiinCallback?>();
_server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
_timer = Timer(timeout, () => _complete(null));
_server!.listen(_handle, onDone: () => _complete(null));
// Best-effort IPv6 loopback on the same port: a redirect addressed
// `localhost` can resolve to `::1` (gh-1044 review) — the fallback
// leg must answer there too. Optional: no IPv6, no problem.
try {
_server6 = await HttpServer.bind(
InternetAddress.loopbackIPv6,
_server!.port,
v6Only: true,
);
_server6!.listen(_handle, onDone: () => _complete(null));
} on IOException catch (error) {
_server6 = null;
stderr.writeln(
'[AIIN] no IPv6 loopback listener (the fallback leg stays '
'IPv4-only): $error',
);
}
return callbackUrl!;
}