From 1f4391123df99562ae1e90c22f042097e3dd26a8 Mon Sep 17 00:00:00 2001 From: Jackabomb <48334975+Jackabomb@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:14:52 -0700 Subject: [PATCH] Try both hostnames, one after another, and take whichever succeeds. Instead of using always "127.0.0.1" or "localhost", try both (preferring "127.0.0.1"). --- KeeAnywhere/OAuth2/OidcSystemBrowser.cs | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/KeeAnywhere/OAuth2/OidcSystemBrowser.cs b/KeeAnywhere/OAuth2/OidcSystemBrowser.cs index 436aa1e..d4ef63b 100644 --- a/KeeAnywhere/OAuth2/OidcSystemBrowser.cs +++ b/KeeAnywhere/OAuth2/OidcSystemBrowser.cs @@ -35,20 +35,24 @@ private static bool CreateListener(out string redirectUri, out HttpListener list ports = Enumerable.Range(49215, 16321); } + string[] hosts = { "127.0.0.1", "localhost" }; foreach (var port in ports) { - redirectUri = CreateRedirectUri(port); - listener = new HttpListener(); - listener.Prefixes.Add(redirectUri); - try + foreach (var host in hosts) { - listener.Start(); + redirectUri = CreateRedirectUri(host, port); + listener = new HttpListener(); + listener.Prefixes.Add(redirectUri); + try + { + listener.Start(); - return true; - } - catch - { - // nothing to do here -- the listener disposes itself when Start throws + return true; + } + catch + { + // nothing to do here -- the listener disposes itself when Start throws + } } } @@ -58,9 +62,9 @@ private static bool CreateListener(out string redirectUri, out HttpListener list return false; } - private static string CreateRedirectUri(int port) + private static string CreateRedirectUri(string host, int port) { - return "http://localhost:" + port + "/"; + return "http://" + host + ":" + port + "/"; } public string RedirectUri