Initial commit: AetherForge Linux (forge-mesh) v0.1.0-dev
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
This commit is contained in:
28
internal/api/handlers/auth.go
Normal file
28
internal/api/handlers/auth.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"forge-mesh/internal/auth"
|
||||
)
|
||||
|
||||
// AuthHandlers serves login and WS ticket endpoints.
|
||||
type AuthHandlers struct {
|
||||
Tickets *auth.TicketStore
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) WSTicket(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
ticket, err := h.Tickets.Issue()
|
||||
if err != nil {
|
||||
http.Error(w, "ticket error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"ticket": ticket})
|
||||
}
|
||||
Reference in New Issue
Block a user