From 58b7afdf1eee6e85c930ca8f544ce71aaebbbfe9 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Wed, 23 Jul 2025 05:09:05 +0800 Subject: [PATCH] Enhance HTTP server with custom multiplexer in Auth flow - Replaced default `http` handler with `http.ServeMux` for improved routing control. - Refactored callback handling to utilize the custom multiplexer. --- internal/auth/auth.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 0a41c8c3..89d6c3dd 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -168,11 +168,12 @@ func getTokenFromWeb(ctx context.Context, config *oauth2.Config) (*oauth2.Token, codeChan := make(chan string) errChan := make(chan error) - // Create a new HTTP server. - server := &http.Server{Addr: ":8085"} + // Create a new HTTP server with its own multiplexer. + mux := http.NewServeMux() + server := &http.Server{Addr: ":8085", Handler: mux} config.RedirectURL = "http://localhost:8085/oauth2callback" - http.HandleFunc("/oauth2callback", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/oauth2callback", func(w http.ResponseWriter, r *http.Request) { if err := r.URL.Query().Get("error"); err != "" { _, _ = fmt.Fprintf(w, "Authentication failed: %s", err) errChan <- fmt.Errorf("authentication failed via callback: %s", err)