@@ -16,7 +16,6 @@ import (
16
16
"strings"
17
17
18
18
"github.com/crewjam/saml/samlsp"
19
- "github.com/kr/pretty"
20
19
)
21
20
22
21
var links = map [string ]Link {}
@@ -67,6 +66,27 @@ func ListLinks(w http.ResponseWriter, r *http.Request) {
67
66
}
68
67
}
69
68
69
+ // ServeWhoami serves the basic whoami endpoint
70
+ func ServeWhoami (w http.ResponseWriter , r * http.Request ) {
71
+ w .Header ().Add ("Content-Type" , "text/plain" )
72
+
73
+ session := samlsp .SessionFromContext (r .Context ())
74
+ if session == nil {
75
+ fmt .Fprintln (w , "not signed in" )
76
+ return
77
+ }
78
+ fmt .Fprintln (w , "signed in" )
79
+ sessionWithAttrs , ok := session .(samlsp.SessionWithAttributes )
80
+ if ok {
81
+ fmt .Fprintln (w , "attributes:" )
82
+ for name , values := range sessionWithAttrs .GetAttributes () {
83
+ for _ , value := range values {
84
+ fmt .Fprintf (w , "%s: %v\n " , name , value )
85
+ }
86
+ }
87
+ }
88
+ }
89
+
70
90
var (
71
91
key = []byte (`-----BEGIN RSA PRIVATE KEY-----
72
92
MIICXgIBAAKBgQDU8wdiaFmPfTyRYuFlVPi866WrH/2JubkHzp89bBQopDaLXYxi
@@ -157,12 +177,7 @@ func main() {
157
177
mux := http .NewServeMux ()
158
178
mux .Handle ("GET /saml/" , samlSP )
159
179
mux .HandleFunc ("GET /{link}" , ServeLink )
160
- mux .Handle ("GET /whoami" , samlSP .RequireAccount (http .HandlerFunc (
161
- func (w http.ResponseWriter , r * http.Request ) {
162
- if _ , err := pretty .Fprintf (w , "%# v" , r ); err != nil {
163
- panic (err )
164
- }
165
- })))
180
+ mux .Handle ("GET /whoami" , samlSP .RequireAccount (http .HandlerFunc (ServeWhoami )))
166
181
mux .Handle ("POST /" , samlSP .RequireAccount (http .HandlerFunc (CreateLink )))
167
182
mux .Handle ("GET /" , samlSP .RequireAccount (http .HandlerFunc (ListLinks )))
168
183
0 commit comments