A lightweight library for encoding & decoding JSON Web Tokens (JWTs).
- Set the HMAC algorithm signing secret as the environment variable
MINIMAL_JWT_SIGNATURE_SECRET. If environment variable is not set, an empty string would be used as the signing secret. - Include the dependency by either adding
gem 'minimal_jwt'in yourGemfileor rungem install minimal_jwtin your terminal in the directory of your codebase. - Require the library by adding
require 'minimal_jwt'wherever the library needs to be utilized.
Use
JWT.encode(payload: your_payload_json)
to encode your payload JSON
You can instantiate a JWT object with any token. There are methods exposed on the object, such as:
valid?- tells you if the token is a well-formed JWT or notheader- returns the header component of the JWT as a hashpayload- returns the payload component of the JWT as a hashsignature_verified?- tells you if the signature component of the token can be verified or not using the signing secret