A faithful Go package for JWT and refresh token management. Keeps your auth tokens on a tight leash.
This project intends to be little more than a silly-themed wrapper around parts of golang-jwt, preconfigured with some hopefully sensible defaults for the basic functions that a casual/personal project might need.
- Simple JWT creation and validation (golang-jwt/SigningMethodHS256)
- Refresh token generation
- Basic verification that token configuration is valid
- Minimal dependencies
- Pull the package with:
go get github.com/Laelapa/guarddoggo
- then import it in your code with:
import "github.com/Laelapa/guarddoggo"
Adopt your very own guard doggo, even consider giving it an affectionate nickname:
azor := guarddoggo.Adopt()
Train it in JWT handling:
azor, err := azor.TrainedInJWT(
"your-jwt-secret-here",
"your-app-name",
24*time.Hour, // Example token lifetime
)
if err != nil {
// Handle training error
}
Command it to fetch you a fresh JWT:
token, err := azor.JWT().Fetch("user123")
if err != nil {
// Handle token creation error
}
Have it sniff out spoiled jwts:
userID, err := azor.JWT().Sniff(token)
if err != nil {
// Handle invalid token error
}
Train it in refresh token hunting:
azor, err = azor.TrainedInRT(
32, // Example token size in bytes
7*24*time.Hour, // Example token lifetime
)
if err != nil {
// Handle training error
}
Command it to fetch you a new refresh token:
refreshToken, err := azor.RT().Fetch()
if err != nil {
// Handle refresh token creation error
}
Stuff that might be added in the future if I end up needing it in my other projects:
- Custom claims for jwts
- Assymetric signing option
- More utility functions