From 06c5fadb42c7888871530bff7699a0e401f33705 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 30 Oct 2024 23:39:09 +0800 Subject: [PATCH] :boom: Change read jwt SDK api --- pkg/nex/sec/jwt_reader.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/nex/sec/jwt_reader.go b/pkg/nex/sec/jwt_reader.go index bfc4d2b..ac80b8f 100644 --- a/pkg/nex/sec/jwt_reader.go +++ b/pkg/nex/sec/jwt_reader.go @@ -39,8 +39,7 @@ func NewJwtReader(fp string) (*JwtReader, error) { }, nil } -func ReadJwt[T jwt.Claims](v *JwtReader, in string) (T, error) { - var out T +func ReadJwt(v *JwtReader, in string, out jwt.Claims) (any, error) { token, err := jwt.ParseWithClaims(in, out, func(token *jwt.Token) (interface{}, error) { if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) @@ -53,9 +52,5 @@ func ReadJwt[T jwt.Claims](v *JwtReader, in string) (T, error) { return out, fmt.Errorf("token is not valid") } - if claims, ok := token.Claims.(T); ok { - return claims, nil - } else { - return out, err - } + return token.Claims, err }