JWT Auth Utils

Generating, signing, and validating JSON Web Tokens (JWT) for secure REST APIs and user sessions.

Lord1Egypt Updated 2 repo stars

File contents

Jwt Auth Utils

Overview

JWT is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties.

When to Use This Skill

Use to implement token-based session validation in stateless web APIs.

Quick Start (with runnable code examples)

import jwt
from datetime import datetime, timedelta, timezone

SECRET_KEY = "super-secret"

# Create a token
payload = {"user_id": 5814716109, "exp": datetime.now(timezone.utc) + timedelta(hours=1)}
token = jwt.encode(payload, SECRET_KEY, algorithm="HS256")
print("Token:", token)

# Decode a token
decoded = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
print("Decoded User ID:", decoded["user_id"])

Advanced Usage

Manage token expiration exceptions, refresh token rotation, and RS256 asymmetric signatures.

Key References

Dependencies

  • PyJWT>=2.8.0

Lord1Egypt/ai-skillforge/tree/main/skills/gemini/jwt-auth-utils commit a96a3c4d72

Frequently asked questions

npx skillmds@latest add lord1egypt/jwt-auth-utils