feat: add yggdrasil metadata endpoint and support authlib-injector

This commit is contained in:
2026-01-29 17:08:52 +03:00
parent a1e022e966
commit f1d763e056
4 changed files with 88 additions and 2 deletions

View File

@@ -12,7 +12,9 @@ import (
)
type AuthHandler struct {
Service *core.AuthService
Service *core.AuthService
ProfileService *core.ProfileService
Domain string
}
// YggdrasilError - стандартный формат ошибки для authserver
@@ -126,3 +128,27 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}
func (h *AuthHandler) GetMetadata(w http.ResponseWriter, r *http.Request) {
pubKey, err := h.ProfileService.GetPublicKey()
if err != nil {
slog.Error("Failed to get public key", "error", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
metadata := models.YggdrasilMetadata{
Meta: models.MetaLinks{
Homepage: "https://" + h.Domain,
Register: "https://" + h.Domain + "/register",
},
SkinDomains: models.MetaSkinDomains{
Deny: []string{},
},
Signature: pubKey,
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(metadata)
}