mirror of
https://github.com/Kugelschieber/migo.git
synced 2026-01-18 06:40:29 +00:00
Started API and loading jwt keys.
This commit is contained in:
33
api/debug.go
Normal file
33
api/debug.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/go-chi/jwtauth/v5"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DebugHandler(w http.ResponseWriter, r *http.Request) {
|
||||
_, claims, err := jwtauth.FromContext(r.Context())
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error reading token: %v", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(struct {
|
||||
Claims map[string]any `json:"claims"`
|
||||
}{
|
||||
claims,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling response: %v", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write(data)
|
||||
}
|
||||
Reference in New Issue
Block a user