feat(ESISSO): enhance callback server with detailed logging and improved response handling

This commit is contained in:
2025-09-09 11:01:21 +02:00
parent 3ca3bf8810
commit e72bab7086

View File

@@ -248,6 +248,7 @@ func (s *ESISSO) StartCallbackServerAsync() error {
mux := http.NewServeMux()
mux.HandleFunc(u.Path, func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Callback received: %s %s\n", r.Method, r.URL.String())
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
@@ -256,18 +257,23 @@ func (s *ESISSO) StartCallbackServerAsync() error {
code := q.Get("code")
st := q.Get("state")
if code == "" || st == "" || st != s.state {
fmt.Printf("Invalid SSO response: code=%s, state=%s, expected_state=%s\n", code, st, s.state)
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("Invalid SSO response"))
return
}
fmt.Printf("Exchanging token for code: %s\n", code)
if err := s.exchangeToken(r.Context(), code); err != nil {
fmt.Printf("Token exchange failed: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte("Token exchange failed: " + err.Error()))
return
}
_, _ = io.WriteString(w, "Login successful. You can close this window.")
fmt.Printf("Login successful for character: %s (%d)\n", s.characterName, s.characterID)
w.Header().Set("Content-Type", "text/html")
_, _ = io.WriteString(w, "<html><body><h1>Login successful!</h1><p>You can close this window.</p></body></html>")
go func() {
time.Sleep(200 * time.Millisecond)
time.Sleep(1 * time.Second)
_ = s.server.Shutdown(context.Background())
}()
})
@@ -277,6 +283,7 @@ func (s *ESISSO) StartCallbackServerAsync() error {
return err
}
fmt.Printf("Callback server listening on %s%s\n", hostPort, u.Path)
s.server = &http.Server{Handler: mux}
go func() { _ = s.server.Serve(ln) }()
return nil