Skip to content

Commit a1c6c0c

Browse files
committed
remove gorilla/mux dependency
1 parent 06e8710 commit a1c6c0c

4 files changed

Lines changed: 10 additions & 15 deletions

File tree

‎cmd/id/server.go‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/function61/gokit/net/http/httputils"
1818
"github.com/function61/gokit/os/osutil"
1919
"github.com/function61/id/pkg/httpauth"
20-
"github.com/gorilla/mux"
2120
"gopkg.in/square/go-jose.v2"
2221
)
2322

@@ -27,7 +26,7 @@ var templateFiles embed.FS
2726
var templates, _ = template.ParseFS(templateFiles, "templates/*.html")
2827

2928
func newHttpHandler() (http.Handler, error) {
30-
router := mux.NewRouter()
29+
router := http.NewServeMux()
3130

3231
signer, signerPublicKey, err := loadSignerAndPublicKey()
3332
if err != nil {
@@ -46,7 +45,7 @@ func newHttpHandler() (http.Handler, error) {
4645

4746
userRegistry := newUserRegistry()
4847

49-
router.HandleFunc("/id", func(w http.ResponseWriter, r *http.Request) {
48+
router.HandleFunc("GET /id", func(w http.ResponseWriter, r *http.Request) {
5049
nextValidated, _, err := getValidatedNext(r, redirectAllowList)
5150
if err != nil {
5251
http.Error(w, err.Error(), http.StatusBadRequest)
@@ -66,9 +65,9 @@ func newHttpHandler() (http.Handler, error) {
6665
}); err != nil {
6766
panic(err)
6867
}
69-
}).Methods(http.MethodGet)
68+
})
7069

71-
router.HandleFunc("/id", func(w http.ResponseWriter, r *http.Request) {
70+
router.HandleFunc("POST /id", func(w http.ResponseWriter, r *http.Request) {
7271
nextValidated, audience, err := getValidatedNext(r, redirectAllowList)
7372
if err != nil {
7473
http.Error(w, err.Error(), http.StatusBadRequest)
@@ -110,9 +109,9 @@ func newHttpHandler() (http.Handler, error) {
110109

111110
httputils.NoCacheHeaders(w)
112111
http.Redirect(w, r, nextValidated.String(), http.StatusFound)
113-
}).Methods(http.MethodPost)
112+
})
114113

115-
router.HandleFunc("/id/profile", func(w http.ResponseWriter, r *http.Request) {
114+
router.HandleFunc("GET /id/profile", func(w http.ResponseWriter, r *http.Request) {
116115
auth, err := authenticator.Authenticate(r)
117116
if err != nil {
118117
http.Error(w, err.Error(), http.StatusForbidden)
@@ -129,15 +128,15 @@ func newHttpHandler() (http.Handler, error) {
129128
_ = jsonfile.Marshal(w, &user)
130129
})
131130

132-
router.HandleFunc("/id/logout", func(w http.ResponseWriter, r *http.Request) {
131+
router.HandleFunc("GET /id/logout", func(w http.ResponseWriter, r *http.Request) {
133132
httputils.NoCacheHeaders(w)
134133

135134
http.SetCookie(w, httpauth.DeleteLoginCookie())
136135

137136
fmt.Fprintln(w, "You have been logged out.")
138137
})
139138

140-
router.HandleFunc("/id/.well-known/jwks.json", func(w http.ResponseWriter, r *http.Request) {
139+
router.HandleFunc("GET /id/.well-known/jwks.json", func(w http.ResponseWriter, r *http.Request) {
141140
// https://tools.ietf.org/html/rfc7517
142141
w.Header().Set("Content-Type", "application/jwk-set+json")
143142
_, _ = w.Write(signerPubKeySetJson)

‎go.mod‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.22
55
require (
66
github.com/aws/aws-lambda-go v1.47.0
77
github.com/function61/gokit v0.0.0-20240419102346-a5f721139a62
8-
github.com/gorilla/mux v1.7.4
98
github.com/kataras/jwt v0.1.2
109
github.com/patrickmn/go-cache v2.1.0+incompatible
1110
github.com/spf13/cobra v1.6.1

‎go.sum‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ github.com/function61/gokit v0.0.0-20240419102346-a5f721139a62 h1:COUqRRf8I+Ppzf
99
github.com/function61/gokit v0.0.0-20240419102346-a5f721139a62/go.mod h1:sJY957+7ush4oj4ElOMhUFaFIriAFNAGYzVh2tFJNy0=
1010
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1111
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
12-
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
13-
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
1412
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
1513
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1614
github.com/kataras/jwt v0.1.2 h1:827BBMK2/PQc1Y209cPKeAChyx1mvfW9I3LE0GJ5V8A=

‎pkg/idclient/authgateway.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/function61/gokit/net/http/httputils"
1212
"github.com/function61/id/pkg/httpauth"
13-
"github.com/gorilla/mux"
1413
)
1514

1615
type GatewayApi struct {
@@ -23,7 +22,7 @@ type GatewayApi struct {
2322
// This auth gateway is required because the identity server cannot set cookies on our behalf.
2423
// The auth gateway simply takes the auth token from URL param, sets cookie and redirects forward.
2524

26-
func (c *Client) CreateAuthGateway(router *mux.Router, audience string) *GatewayApi {
25+
func (c *Client) CreateAuthGateway(router *http.ServeMux, audience string) *GatewayApi {
2726
// we used to fetch the public key here, but that's not ideal. this CreateAuthGateway() is usually
2827
// called on application startup to protect specified/all HTTP routes. if we were to error here,
2928
// perhaps because network is down, it'd prevent starting the HTTP app.
@@ -123,7 +122,7 @@ func (g *GatewayApi) loginUrlContinueToGateway(continueAfterGateway string, r *h
123122
return g.client.loginUrl(gateway)
124123
}
125124

126-
func (g *GatewayApi) registerGatewayRoutes(router *mux.Router) *GatewayApi {
125+
func (g *GatewayApi) registerGatewayRoutes(router *http.ServeMux) *GatewayApi {
127126
// logs the user out from this website, but also the identity server
128127
router.HandleFunc("/_auth/logout", func(w http.ResponseWriter, r *http.Request) {
129128
httputils.NoCacheHeaders(w)

0 commit comments

Comments
 (0)