ServeWhoami serves the basic whoami endpoint
(w http.ResponseWriter, r *http.Request)
| 155 | |
| 156 | // ServeWhoami serves the basic whoami endpoint |
| 157 | func 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. |
nothing calls this directly
no test coverage detected