Started API and loading jwt keys.

This commit is contained in:
2023-07-19 17:29:15 +02:00
committed by Marvin Blum
parent 7443478acc
commit 22467bc3b4
5 changed files with 138 additions and 22 deletions

33
api/debug.go Normal file
View 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)
}