MCPcopy Create free account
hub / github.com/crewjam/saml / ServeWhoami

Function ServeWhoami

example/service.go:157–175  ·  view source on GitHub ↗

ServeWhoami serves the basic whoami endpoint

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

155
156// ServeWhoami serves the basic whoami endpoint
157func ServeWhoami(w http.ResponseWriter, r *http.Request) {
158 w.Header().Add("Content-Type", "text/plain")
159
160 session := samlsp.SessionFromContext(r.Context())
161 if session == nil {
162 writeText(w, "not signed in\n")
163 return
164 }
165 writeText(w, "signed in\n")
166 sessionWithAttrs, ok := session.(samlsp.SessionWithAttributes)
167 if ok {
168 writeText(w, "attributes:\n")
169 for name, values := range sessionWithAttrs.GetAttributes() {
170 for _, value := range values {
171 writeText(w, "%s: %v\n", name, value)
172 }
173 }
174 }
175}
176
177// writeText writes a formatted line of the response. An error writing to the
178// client cannot be reported back to it, so it is deliberately ignored.

Callers

nothing calls this directly

Calls 4

SessionFromContextFunction · 0.92
writeTextFunction · 0.85
GetAttributesMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected