Private
Public Access
27 lines
550 B
Go
27 lines
550 B
Go
package jwtutils
|
|
|
|
import (
|
|
"github.com/golang-jwt/jwt/v5"
|
|
)
|
|
|
|
var JWTSecret = os.GetEnv("JWTSecret")
|
|
|
|
func ValidarJWT(tokenString string) (jwt.MapClaims, error) {
|
|
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
|
return nil, jwt.ErrSignatureInvalid
|
|
}
|
|
return JWTSecret, nil
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
claims, ok := token.Claims.(jwt.MapClaims)
|
|
if !ok || !token.Valid {
|
|
return nil, jwt.ErrSignatureInvalid
|
|
}
|
|
|
|
return claims, nil
|
|
}
|