From 591581cbc296edf747a355b699aa8ede6319edf1 Mon Sep 17 00:00:00 2001 From: KynixInHK Date: Wed, 10 Jul 2024 13:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=E4=BA=86jwt=E9=9D=9E?= =?UTF-8?q?=E5=B0=8D=E7=A8=B1=E5=8A=A0=E5=AF=86=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- am_jwt/jwt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/am_jwt/jwt.go b/am_jwt/jwt.go index fb6d67d..4a15c31 100644 --- a/am_jwt/jwt.go +++ b/am_jwt/jwt.go @@ -68,6 +68,7 @@ type TokenClaims struct { Exp int // token过期时间,以秒计数 Issuer string // 签发人 SECRET string // token secret + PUBLIC string // token public jwt.StandardClaims // standard claims,无需用户设定 } @@ -117,11 +118,12 @@ func GenToken(claims *TokenClaims) (string, error) { Issuer: claims.Issuer, // 签发人 } - // 解析私鑰 + // 解析並刪除私鑰 privKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(claims.SECRET)) if err != nil { return "", err } + tokenClaims.SECRET = "" // 生成token字串 tokenGenerator := jwt.NewWithClaims(jwt.SigningMethodRS256, tokenClaims)