Skip to content

Commit 8c28e23

Browse files
committed
add error checking using token.Valid instead remove the check for the signature vmware-archive#73
1 parent 5658727 commit 8c28e23

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cmd/gangway/handlers.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,28 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
188188

189189
func parseToken(idToken string) (*jwt.Token, error) {
190190
token, err := jwt.Parse(idToken, func(token *jwt.Token) (interface{}, error) {
191-
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
192-
return nil, fmt.Errorf("Unexpected signing method")
193-
}
194191
return []byte(cfg.ClientSecret), nil
195192
})
196193
if err != nil {
197194
return nil, err
198195
}
199-
return token, nil
196+
if token.Valid {
197+
return token, nil
198+
} else if ve, ok := err.(*jwt.ValidationError); ok {
199+
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
200+
log.Println("That's not even a token")
201+
return nil, err
202+
} else if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
203+
log.Println("Timing is everything")
204+
return nil, err
205+
} else {
206+
log.Errorf("Couldn't handle this token:%s", err)
207+
return nil, err
208+
}
209+
} else {
210+
log.Errorf("Couldn't handle this token:%s", err)
211+
return nil, err
212+
}
200213
}
201214

202215
func commandlineHandler(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)