Skip to content

Instantly share code, notes, and snippets.

@GarupanOjisan
Created January 12, 2020 20:20
Show Gist options
  • Save GarupanOjisan/d8cec6903856dfd58e9efa1c8bd8f3aa to your computer and use it in GitHub Desktop.
Save GarupanOjisan/d8cec6903856dfd58e9efa1c8bd8f3aa to your computer and use it in GitHub Desktop.
verifying jwt
func verifyJWT(publicKeyPath string, token string) (bool, error) {
t, err := jwt.Parse(token, func(token *jwt.Token) (i interface{}, err error) {
if token.Method != (jwt.SigningMethodRS256) {
return nil, fmt.Errorf("invalid signing method")
}
verifyBytes, err := ioutil.ReadFile(publicKeyPath)
if err != nil {
return nil, err
}
return jwt.ParseRSAPublicKeyFromPEM(verifyBytes)
})
if err != nil {
return false, err
}
return t.Valid, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment