Created
January 12, 2020 20:20
-
-
Save GarupanOjisan/d8cec6903856dfd58e9efa1c8bd8f3aa to your computer and use it in GitHub Desktop.
verifying jwt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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