Documentation
¶
Overview ¶
Example: Auth — JWT-like Authentication with HMAC-SHA256
Demonstrates a token-based authentication pattern using ONLY stdlib crypto packages (no external JWT library):
- HMAC-SHA256 token generation and validation
- Login endpoint that issues tokens
- Auth middleware that validates tokens on protected routes
- Token payload with expiration
This is a simplified JWT-like pattern. For production, consider a full JWT library or Kruda's future contrib/jwt package.
Run: go run -tags kruda_stdjson ./examples/auth/ Test:
curl http://localhost:3000/ → public
curl -X POST http://localhost:3000/login -d '{"username":"admin","password":"secret"}'
curl http://localhost:3000/protected -H "Authorization: Bearer <token>"
Click to show internal directories.
Click to hide internal directories.