diff --git a/main.go b/main.go index 682bd30..3f990e4 100644 --- a/main.go +++ b/main.go @@ -69,17 +69,26 @@ func main() { logger.Error("Server failed: %v", err) } }() - - // Get token for character (this will add callback route temporarily) - token, err := sso.GetToken(context.Background(), "PhatPhuckDave") - if err != nil { - logger.Error("Failed to get token %v", err) - return - } - - logger.Info("Got token %s", token) - // Use the token for ESI API calls - // The SSO handles all the complexity behind the scenes + + mux.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) { + charName := r.URL.Query().Get("character") + if charName == "" { + http.Error(w, "Missing character parameter", http.StatusBadRequest) + return + } + logger.Info("Login requested for character %s", charName) + // Trigger the auth flow (will register callback if needed) + token, err := sso.GetToken(r.Context(), charName) + if err != nil { + logger.Error("Failed to authenticate character %s: %v", charName, err) + http.Error(w, "Authentication failed", http.StatusInternalServerError) + return + } + logger.Info("Successfully authenticated character %s", charName) + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + w.Write([]byte("Authenticated! Access token: " + token)) + }) } func LoadOptions() (Options, error) {