From 463e6113e4872028e5d6f717f8f192ac9911a7d8 Mon Sep 17 00:00:00 2001 From: Tamalampudi Siva Harsha Vardhan Reddy <2400030361@kluniversity.in> Date: Mon, 24 Nov 2025 18:38:27 +0530 Subject: [PATCH 1/2] feat(auth): enable OS port selection for OAuth server Use port 0 to allow OS to automatically assign available port, removing hardcoded port range (8000-8010) from _prepare_server method. This resolves port conflict issues when the OAuth server fails to bind to predefined ports. Fixes #913 Refactor server preparation to use a dynamic port. --- ggshield/verticals/auth/oauth.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/ggshield/verticals/auth/oauth.py b/ggshield/verticals/auth/oauth.py index 73fc4f91e5..096eff152d 100644 --- a/ggshield/verticals/auth/oauth.py +++ b/ggshield/verticals/auth/oauth.py @@ -104,7 +104,7 @@ def oauth_process( if extra_scopes is not None: self._extra_scopes = extra_scopes - self._prepare_server() + self.158() self._redirect_to_login() self._wait_for_callback() self._print_login_success() @@ -163,20 +163,11 @@ def _redirect_to_login(self) -> None: webbrowser.open_new_tab(request_uri) def _prepare_server(self) -> None: - for port in range(*USABLE_PORT_RANGE): - try: - self.server = HTTPServer( - # only consider requests from localhost on the predetermined port - ("127.0.0.1", port), - functools.partial(RequestHandler, self), - ) - self._port = port - break - except OSError: - continue - else: - raise UnexpectedError("Could not find unoccupied port.") - +self.server = HTTPServer( + ("127.0.0.1", 0), + functools.partial(RequestHandler, self), + ) + self._port = self.server.server_port def _wait_for_callback(self) -> None: """ Wait to receive and process the authorization callback on the local server. From 704e9aab2353f8cf921e6eb23ea4f40d4edffc4d Mon Sep 17 00:00:00 2001 From: harsha08-2k6 <2400030361@kluniversity.in> Date: Wed, 26 Nov 2025 10:55:29 +0530 Subject: [PATCH 2/2] fix: remove invalid method call --- ggshield/verticals/auth/oauth.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ggshield/verticals/auth/oauth.py b/ggshield/verticals/auth/oauth.py index 096eff152d..1dbbf10088 100644 --- a/ggshield/verticals/auth/oauth.py +++ b/ggshield/verticals/auth/oauth.py @@ -104,7 +104,6 @@ def oauth_process( if extra_scopes is not None: self._extra_scopes = extra_scopes - self.158() self._redirect_to_login() self._wait_for_callback() self._print_login_success()