Add a login route to simply add characters

This commit is contained in:
2025-10-10 20:12:36 +02:00
parent f521c7e449
commit 1e5ac81598

29
main.go
View File

@@ -70,16 +70,25 @@ func main() {
}
}()
// 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) {