feat: revoke service session

This commit is contained in:
2025-06-15 19:40:54 +02:00
parent 03bf655051
commit c5fb5e674a
2 changed files with 25 additions and 0 deletions

View File

@ -40,6 +40,7 @@ func (h *AdminHandler) RegisterRoutes(router chi.Router) {
r.Patch("/user-sessions/revoke/{id}", h.RevokeUserSession)
r.Get("/service-sessions", h.GetServiceSessions)
r.Patch("/service-sessions/revoke/{id}", h.RevokeUserSession)
})
router.Get("/api-services/client/{client_id}", h.GetApiServiceCID)

View File

@ -73,6 +73,8 @@ func (h *AdminHandler) GetUserSessions(w http.ResponseWriter, r *http.Request) {
TotalPages: int(math.Ceil(float64(totalSessions) / float64(params.PageSize))),
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
log.Println("ERR: Failed to encode sessions in response:", err)
web.Error(w, "failed to encode sessions", http.StatusInternalServerError)
@ -94,6 +96,8 @@ func (h *AdminHandler) RevokeUserSession(w http.ResponseWriter, r *http.Request)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte("{\"success\":true}"))
}
@ -151,8 +155,28 @@ func (h *AdminHandler) GetServiceSessions(w http.ResponseWriter, r *http.Request
TotalPages: int(math.Ceil(float64(totalSessions) / float64(params.PageSize))),
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
log.Println("ERR: Failed to encode sessions in response:", err)
web.Error(w, "failed to encode sessions", http.StatusInternalServerError)
}
}
func (h *AdminHandler) RevokeServiceSession(w http.ResponseWriter, r *http.Request) {
sessionId := chi.URLParam(r, "id")
parsed, err := uuid.Parse(sessionId)
if err != nil {
web.Error(w, "provided service id is not valid", http.StatusBadRequest)
return
}
if err := h.repo.RevokeServiceSession(r.Context(), parsed); err != nil {
log.Println("ERR: Failed to revoke service session:", err)
web.Error(w, "failed to revoke service session", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("{\"success\":true}"))
}