feat(auth): implement yggdrasil join endpoint

This commit is contained in:
2025-06-15 17:17:50 +03:00
parent 056aa05c50
commit 9082b21a5d
5 changed files with 107 additions and 1 deletions

View File

@@ -49,3 +49,32 @@ func (h *AuthHandler) Authenticate(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}
func (h *AuthHandler) Join(w http.ResponseWriter, r *http.Request) {
var req models.JoinRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
err := h.Service.ValidateJoinRequest(r.Context(), req)
if err != nil {
// Yggdrasil ожидает 403 Forbidden при невалидной сессии
if errors.Is(err, core.ErrInvalidCredentials) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusForbidden)
json.NewEncoder(w).Encode(YggdrasilError{
Error: "ForbiddenOperationException",
ErrorMessage: "Invalid token.",
})
return
}
log.Printf("internal server error during join: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
// В случае успеха возвращаем пустой ответ со статусом 204
w.WriteHeader(http.StatusNoContent)
}