Skip to content

Commit

Permalink
feat: apply jwt ed25519 signing method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Apr 3, 2024
1 parent e40a3c4 commit 071f65b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/pkg/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"time"
)

var key = []byte(global.Config.Jwt.SignKey)

const (
User = "User"
Login = "Login"
Expand Down Expand Up @@ -73,14 +71,14 @@ func NewUserClaims(uid uint, Type string, valid time.Duration) (claims jwtClaims
}

func GenerateToken(claims jwtClaims.Claims) (string, error) {
return jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString(key)
return jwt.NewWithClaims(&jwt.SigningMethodEd25519{}, claims).SignedString(global.JwtEd25519.PrivateKey)
}

func ParseToken[C jwtClaims.Claims](Type, token string, target C) (claims C, valid bool, err error) {
var t *jwt.Token
t, err = jwt.ParseWithClaims(
token, target, func(t *jwt.Token) (interface{}, error) {
return key, nil
return global.JwtEd25519.PublicKey, nil
},
jwt.WithLeeway(time.Second*3),
)
Expand Down

0 comments on commit 071f65b

Please sign in to comment.