feat(auth): implement yggdrasil join endpoint
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user