February 2020
Intermediate to advanced
404 pages
8h 42m
English
jwt-go also gives us the API to parse a given JWT string. The Parse function takes a string and key function as arguments. The key function is a custom function that validates whether the algorithm is real or not. Let us say this is a sample token string generated by the preceding encoding:
tokenString = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoiMTUwODc0MTU5MTQ2NiJ9.5m6KkuQFCgyaGS_xcVy4xWakwDgtAG3ILGGTBgYVBmE"
We can parse and get back the original JSON using the following code:
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { // key function if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { return nil, fmt.Errorf("Unexpected signing method: %v", ...Read now
Unlock full access