package route import ( "encoding/json" "net/http" oidc "forge.cadoles.com/wpetit/goweb-oidc" "github.com/pkg/errors" "gitlab.com/wpetit/goweb/middleware/container" "gitlab.com/wpetit/goweb/service/template" ) func serveProfilePage(w http.ResponseWriter, r *http.Request) { ctn := container.Must(r.Context()) tmpl := template.Must(ctn) idToken, err := oidc.IDToken(w, r) if err != nil { panic(errors.Wrap(err, "could not retrieve idToken")) } claims := make(map[string]interface{}) if err := idToken.Claims(&claims); err != nil { panic(errors.Wrap(err, "could not decode claims")) } jsonIDToken, err := json.MarshalIndent(idToken, "", " ") if err != nil { panic(errors.Wrap(err, "could not encode idToken")) } jsonClaims, err := json.MarshalIndent(claims, "", " ") if err != nil { panic(errors.Wrap(err, "could not encode claims")) } data := extendTemplateData(w, r, template.Data{ "IDToken": idToken, "Claims": claims, "JSONClaims": string(jsonClaims), "JSONIDToken": string(jsonIDToken), }) if err := tmpl.RenderPage(w, "profile.html.tmpl", data); err != nil { panic(errors.Wrapf(err, "could not render '%s' page", r.URL.Path)) } }