From cbad236a7f6b70b1f6a9f6f42bbc8645b087e041 Mon Sep 17 00:00:00 2001
From: Jackabomb <48334975+Jackabomb@users.noreply.github.com>
Date: Sat, 18 Sep 2021 08:29:13 -0700
Subject: [PATCH 1/2] Changed OidcBrowser url from 127.0.0.1 to localhost.
 Fixes #301.

---
 KeeAnywhere/OAuth2/OidcSystemBrowser.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/KeeAnywhere/OAuth2/OidcSystemBrowser.cs b/KeeAnywhere/OAuth2/OidcSystemBrowser.cs
index 4a6c79c..436aa1e 100644
--- a/KeeAnywhere/OAuth2/OidcSystemBrowser.cs
+++ b/KeeAnywhere/OAuth2/OidcSystemBrowser.cs
@@ -60,7 +60,7 @@ private static bool CreateListener(out string redirectUri, out HttpListener list
 
         private static string CreateRedirectUri(int port)
         {
-            return "http://127.0.0.1:" + port + "/";
+            return "http://localhost:" + port + "/";
         }
 
         public string RedirectUri

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 2/2] 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