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) mux.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
token, err := sso.GetToken(context.Background(), "PhatPhuckDave") charName := r.URL.Query().Get("character")
if err != nil { if charName == "" {
logger.Error("Failed to get token %v", err) http.Error(w, "Missing character parameter", http.StatusBadRequest)
return return
} }
logger.Info("Login requested for character %s", charName)
logger.Info("Got token %s", token) // Trigger the auth flow (will register callback if needed)
// Use the token for ESI API calls token, err := sso.GetToken(r.Context(), charName)
// The SSO handles all the complexity behind the scenes 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) { func LoadOptions() (Options, error) {