Encode JWT properly

I'm trying to write simple JWT implementation with these functionalities: Generating token using HMAC Validating token (if signature is correct or exp is not timed out) Decode token and getting cl...