github.com/uvalib/orcid-access-ws@v0.0.0-20250612130209-7d062dbabf9d/orcidaccessws/authtoken/validate.go (about) 1 package authtoken 2 3 import ( 4 "fmt" 5 "github.com/dgrijalva/jwt-go" 6 "github.com/uvalib/orcid-access-ws/orcidaccessws/logger" 7 "time" 8 ) 9 10 // Validate -- called to validate the supplied token 11 func Validate(sharedSecret string, token string) bool { 12 13 // Initialize a new instance of the standard claims 14 claims := &jwt.StandardClaims{} 15 16 tkn, err := jwt.ParseWithClaims(token, claims, func(token *jwt.Token) (interface{}, error) { 17 return []byte(sharedSecret), nil 18 }) 19 20 if err != nil { 21 logger.Log(fmt.Sprintf("ERROR: JWT parse returns: %s", err.Error())) 22 return false 23 } 24 25 if !tkn.Valid { 26 logger.Log(fmt.Sprintf("ERROR: JWT is INVALID")) 27 return false 28 } else { 29 logger.Log(fmt.Sprintf("INFO: token is valid, Expires %s", time.Unix(claims.ExpiresAt, 0))) 30 } 31 return true 32 } 33 34 // 35 // end of file 36 //