2026-05-07 23:51:16 -06:00
|
|
|
// Package httpauthjwt provides self-issued JWT authentication middleware and token
|
2026-05-07 22:18:04 -06:00
|
|
|
// management for HTTP services.
|
|
|
|
|
//
|
|
|
|
|
// It integrates with code.nochebuena.dev/go/httpauth: AuthMiddleware verifies
|
|
|
|
|
// Bearer tokens and calls httpauth.SetTokenData, making uid and claims available
|
|
|
|
|
// to EnrichmentMiddleware, AuthzMiddleware, and ClaimsPermissionProvider.
|
|
|
|
|
//
|
|
|
|
|
// Typical flow:
|
|
|
|
|
//
|
|
|
|
|
// 1. Issue a token pair on login:
|
|
|
|
|
//
|
2026-05-07 23:51:16 -06:00
|
|
|
// signer := httpauthjwt.NewHMACSigner([]byte(os.Getenv("JWT_SECRET")))
|
|
|
|
|
// pair, err := httpauthjwt.IssueTokenPair(signer, uid, customClaims, cfg)
|
2026-05-07 22:18:04 -06:00
|
|
|
//
|
|
|
|
|
// 2. Protect routes:
|
|
|
|
|
//
|
2026-05-07 23:51:16 -06:00
|
|
|
// r.Use(httpauthjwt.AuthMiddleware(signer, publicPaths))
|
2026-05-07 22:18:04 -06:00
|
|
|
// r.Use(httpauth.EnrichmentMiddleware(myEnricher))
|
|
|
|
|
//
|
|
|
|
|
// 3. Rotate tokens on refresh:
|
|
|
|
|
//
|
2026-05-07 23:51:16 -06:00
|
|
|
// newPair, err := httpauthjwt.RefreshTokenPair(ctx, signer, refreshToken, blacklist, cfg, freshClaims)
|
2026-05-07 22:18:04 -06:00
|
|
|
//
|
|
|
|
|
// For microservices that only verify tokens (not issue them), use NewRSAPublicKeyVerifier
|
|
|
|
|
// or NewRSAPublicKeyVerifierFromPEM with the public key only.
|
2026-05-07 23:51:16 -06:00
|
|
|
package httpauthjwt
|