11package middleware
22
33import (
4- "slices"
54 "strings"
65 "time"
76
@@ -13,7 +12,24 @@ import (
1312 "github.com/gin-gonic/gin"
1413)
1514
16- var OIDCIgnorePaths = []string {"/api/oidc/token" , "/api/oidc/userinfo" }
15+ // Gin won't let us set a middleware on a specific route (at least it doesn't work,
16+ // see https://github.com/gin-gonic/gin/issues/531) so we have to do some hackery
17+ var (
18+ contextSkipPathsPrefix = []string {
19+ "GET /api/context/app" ,
20+ "GET /api/healthz" ,
21+ "HEAD /api/healthz" ,
22+ "GET /api/oauth/url" ,
23+ "GET /api/oauth/callback" ,
24+ "GET /api/oidc/clients" ,
25+ "POST /api/oidc/token" ,
26+ "GET /api/oidc/userinfo" ,
27+ "GET /resources" ,
28+ "POST /api/user/login" ,
29+ "GET /.well-known/openid-configuration" ,
30+ "GET /.well-known/jwks.json" ,
31+ }
32+ )
1733
1834type ContextMiddlewareConfig struct {
1935 CookieDomain string
@@ -39,9 +55,7 @@ func (m *ContextMiddleware) Init() error {
3955
4056func (m * ContextMiddleware ) Middleware () gin.HandlerFunc {
4157 return func (c * gin.Context ) {
42- // There is no point in trying to get credentials if it's an OIDC endpoint
43- path := c .Request .URL .Path
44- if slices .Contains (OIDCIgnorePaths , strings .TrimSuffix (path , "/" )) {
58+ if m .isIgnorePath (c .Request .Method + " " + c .Request .URL .Path ) {
4559 c .Next ()
4660 return
4761 }
@@ -224,3 +238,12 @@ func (m *ContextMiddleware) Middleware() gin.HandlerFunc {
224238 c .Next ()
225239 }
226240}
241+
242+ func (m * ContextMiddleware ) isIgnorePath (path string ) bool {
243+ for _ , prefix := range contextSkipPathsPrefix {
244+ if strings .HasPrefix (path , prefix ) {
245+ return true
246+ }
247+ }
248+ return false
249+ }
0 commit comments