jwt v1

A Go package that provides a simple and secure way to work with JSON Web Tokens (JWT). This package supports both HMAC (secret-based) and RSA (key-based) signing methods.

Repository

Features

  • Simple API for creating and managing JWT claims

  • Support for all standard JWT claims

  • HMAC-SHA256 signing with secret key

  • RSA-SHA256 signing with public/private key pairs

  • Token verification and decoding

  • Custom claim support

Installation

Usage

Creating Claims

Encoding Tokens

Decoding Tokens

Accessing Claims

Standard Claims

The package supports all standard JWT claims:

  • iss (Issuer)

  • sub (Subject)

  • aud (Audience)

  • exp (Expiration Time)

  • nbf (Not Before)

  • iat (Issued At)

  • jti (JWT ID)

Security Considerations

  1. Always use strong secrets or properly generated RSA keys

  2. Set appropriate expiration times for tokens

  3. Avoid using DecodeUnverified in production environments

  4. Keep private keys secure and never expose them

  5. Validate tokens on the server side before trusting their contents

Dependencies

  • github.com/golang-jwt/jwt/v5

  • github.com/metadiv-io/rsa

Last updated