diff --git a/go.mod b/go.mod index 420869f..b21b385 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,7 @@ require ( github.com/golang-jwt/jwt/v5 v5.2.1 github.com/issue9/assert/v4 v4.1.1 github.com/issue9/cache v0.9.2 - github.com/issue9/sliceutil v0.15.1 - github.com/issue9/web v0.87.3 + github.com/issue9/web v0.87.4 ) require ( @@ -16,12 +15,13 @@ require ( github.com/issue9/config v0.6.2 // indirect github.com/issue9/conv v1.3.5 // indirect github.com/issue9/errwrap v0.3.2 // indirect - github.com/issue9/localeutil v0.26.4 // indirect + github.com/issue9/localeutil v0.26.5 // indirect github.com/issue9/logs/v7 v7.5.0 // indirect github.com/issue9/mux/v7 v7.4.1 // indirect github.com/issue9/query/v3 v3.1.3 // indirect github.com/issue9/rands/v2 v2.0.1 // indirect github.com/issue9/scheduled v0.19.3 // indirect + github.com/issue9/sliceutil v0.15.1 // indirect github.com/issue9/source v0.8.2 // indirect github.com/issue9/term/v3 v3.2.7 // indirect github.com/issue9/unique/v2 v2.0.1 // indirect diff --git a/go.sum b/go.sum index c70fafe..6c34e35 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/issue9/conv v1.3.5 h1:UWeA+Zqp5vjNDLrmhLhaXPjS1hL8gh4quX6Shk5njKQ= github.com/issue9/conv v1.3.5/go.mod h1:lkZYMyrmxy+HK//N4eLmwUl9mCwj0zgeTjnxgl/w7hM= github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw= github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A= -github.com/issue9/localeutil v0.26.4 h1:rfBC3YAt9PLHXHc5unreZpYjlEt+xCnVOUr7QDAveiw= -github.com/issue9/localeutil v0.26.4/go.mod h1:BJXJwcAT9CyyVZOlqfmq+B5FcPbqGxGjYnTYbVuiMM8= +github.com/issue9/localeutil v0.26.5 h1:e78b6cOOtgzfb4g4U9uPLC8QyK6Lux+s7ZiQe+6iM1A= +github.com/issue9/localeutil v0.26.5/go.mod h1:BJXJwcAT9CyyVZOlqfmq+B5FcPbqGxGjYnTYbVuiMM8= github.com/issue9/logs/v7 v7.5.0 h1:IAzqaRXuhNzTvoZVwFJWnWOxCiqhsiqxOt3GuAvJaWQ= github.com/issue9/logs/v7 v7.5.0/go.mod h1:zPhcpznbDmfApbtrZHeHDvngfNAcuNhgo9pJfKD8nXY= github.com/issue9/mux/v7 v7.4.1 h1:FG5iu44zd4GVIdzj7/oZgDYBaXnsRnrXWMZANcNhVIk= @@ -42,8 +42,8 @@ github.com/issue9/term/v3 v3.2.7 h1:esfhoinbQ65P3oFscXhticrDFOgZJQqUwL/IC70HiWc= github.com/issue9/term/v3 v3.2.7/go.mod h1:DvA/fPiKzX11P/ZoVWJG5QMVpI0ia+uqiU31iZV2jHE= github.com/issue9/unique/v2 v2.0.1 h1:Tdbq7hWZd7rvnf3ckUqzvEftOBWl1Z3S60Jk/zbPvyM= github.com/issue9/unique/v2 v2.0.1/go.mod h1:oYIXt0BXX4tekc9+77oBu/ROsm7tr5kmD78XEqFoWwk= -github.com/issue9/web v0.87.3 h1:zuUzTpJCvEczOaX0AnXgNWFBimut7kjhUgaWBVKVJ+s= -github.com/issue9/web v0.87.3/go.mod h1:n9sIOcvdTbw1F5ME3ArYPbugH6mf7sqjXk+g0bT2nP4= +github.com/issue9/web v0.87.4 h1:BD6+ZjSCnlYS6G8j0xOJxmjsHkhaOAPP0Oe5OW3z+3M= +github.com/issue9/web v0.87.4/go.mod h1:5nkr+8J/LD1WAyjA/4gmWgi3IOxRV37cR6c3EJ062b8= github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8= diff --git a/middlewares/auth/jwt/verifier.go b/middlewares/auth/jwt/verifier.go index ad801fd..ca55615 100644 --- a/middlewares/auth/jwt/verifier.go +++ b/middlewares/auth/jwt/verifier.go @@ -7,10 +7,10 @@ package jwt import ( "fmt" "io/fs" + "slices" "strings" "github.com/golang-jwt/jwt/v5" - "github.com/issue9/sliceutil" "github.com/issue9/web" ) @@ -60,7 +60,8 @@ func NewVerifier[T Claims](b Blocker[T], f BuildClaimsFunc[T]) *Verifier[T] { } if kid, found := t.Header["kid"]; found { - if k, found := sliceutil.At(j.keys, func(e *key, _ int) bool { return e.id == kid }); found { + if index := slices.IndexFunc(j.keys, func(e *key) bool { return e.id == kid }); index >= 0 { + k := j.keys[index] t.Method = k.sign // 忽略由用户指定的 header['alg'],而是有 kid 指定。 return k.key, nil } @@ -120,7 +121,7 @@ func GetToken(ctx *web.Context) string { } func (j *Verifier[T]) addKey(id string, sign SigningMethod, keyData any) { - if sliceutil.Exists(j.keys, func(e *key, _ int) bool { return e.id == id }) { + if slices.IndexFunc(j.keys, func(e *key) bool { return e.id == id }) >= 0 { panic(fmt.Sprintf("存在同名的签名方法 %s", id)) }