Skip to content

Commit 10fe88b

Browse files
committed
remove pointless dependency on github.com/kr/pretty
1 parent 30fafb0 commit 10fe88b

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

example/service.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"strings"
1717

1818
"github.com/crewjam/saml/samlsp"
19-
"github.com/kr/pretty"
2019
)
2120

2221
var links = map[string]Link{}
@@ -67,6 +66,27 @@ func ListLinks(w http.ResponseWriter, r *http.Request) {
6766
}
6867
}
6968

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+
7090
var (
7191
key = []byte(`-----BEGIN RSA PRIVATE KEY-----
7292
MIICXgIBAAKBgQDU8wdiaFmPfTyRYuFlVPi866WrH/2JubkHzp89bBQopDaLXYxi
@@ -157,12 +177,7 @@ func main() {
157177
mux := http.NewServeMux()
158178
mux.Handle("GET /saml/", samlSP)
159179
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)))
166181
mux.Handle("POST /", samlSP.RequireAccount(http.HandlerFunc(CreateLink)))
167182
mux.Handle("GET /", samlSP.RequireAccount(http.HandlerFunc(ListLinks)))
168183

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/beevik/etree v1.5.0
99
github.com/golang-jwt/jwt/v4 v4.5.2
1010
github.com/google/go-cmp v0.6.0
11-
github.com/kr/pretty v0.3.1
1211
github.com/mattermost/xml-roundtrip-validator v0.1.0
1312
github.com/russellhaering/goxmldsig v1.4.0
1413
github.com/stretchr/testify v1.10.0
@@ -19,9 +18,8 @@ require (
1918
require (
2019
github.com/davecgh/go-spew v1.1.1 // indirect
2120
github.com/jonboulle/clockwork v0.2.2 // indirect
22-
github.com/kr/text v0.2.0 // indirect
21+
github.com/kr/pretty v0.3.1 // indirect
2322
github.com/pkg/errors v0.9.1 // indirect
2423
github.com/pmezard/go-difflib v1.0.0 // indirect
25-
github.com/rogpeppe/go-internal v1.9.0 // indirect
2624
gopkg.in/yaml.v3 v3.0.1 // indirect
2725
)

0 commit comments

Comments
 (0)