Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Created August 14, 2017 13:13
Show Gist options
  • Select an option

  • Save jeffotoni/c457a7682202dbf822f5cc4496b1d3e2 to your computer and use it in GitHub Desktop.

Select an option

Save jeffotoni/c457a7682202dbf822f5cc4496b1d3e2 to your computer and use it in GitHub Desktop.
if token, err := request.ParseFromRequest(r, request.OAuth2Extractor, keyLookupFunc2); err == nil {
claims := token.Claims.(jwt.MapClaims)
fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"])
} else if err != nil {
fmt.Println("Error: ", err)
switch err.(type) {
case *jwt.ValidationError:
vErr := err.(*jwt.ValidationError)
switch vErr.Errors {
case jwt.ValidationErrorExpired:
fmt.Fprintln(w, "Your token has expired!")
return
case jwt.ValidationErrorSignatureInvalid:
fmt.Fprintln(w, "Token signature does not match!")
return
default:
fmt.Fprintln(w, "Your token is invalid!")
return
}
default:
fmt.Fprintln(w, "Your token is invalid!")
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment