mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 04:10:51 +08:00
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.
This commit is contained in:
@@ -168,11 +168,12 @@ func getTokenFromWeb(ctx context.Context, config *oauth2.Config) (*oauth2.Token,
|
|||||||
codeChan := make(chan string)
|
codeChan := make(chan string)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
||||||
// Create a new HTTP server.
|
// Create a new HTTP server with its own multiplexer.
|
||||||
server := &http.Server{Addr: ":8085"}
|
mux := http.NewServeMux()
|
||||||
|
server := &http.Server{Addr: ":8085", Handler: mux}
|
||||||
config.RedirectURL = "http://localhost:8085/oauth2callback"
|
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 != "" {
|
if err := r.URL.Query().Get("error"); err != "" {
|
||||||
_, _ = fmt.Fprintf(w, "Authentication failed: %s", err)
|
_, _ = fmt.Fprintf(w, "Authentication failed: %s", err)
|
||||||
errChan <- fmt.Errorf("authentication failed via callback: %s", err)
|
errChan <- fmt.Errorf("authentication failed via callback: %s", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user