Skip to content

A faithful Go package for JWT and refresh token management. Keeps your auth tokens on a tight leash.

Notifications You must be signed in to change notification settings

Laelapa/guarddoggo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guarddoggo

A faithful Go package for JWT and refresh token management. Keeps your auth tokens on a tight leash.

About

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.

🦮 Features

  • Simple JWT creation and validation (golang-jwt/SigningMethodHS256)
  • Refresh token generation
  • Basic verification that token configuration is valid
  • Minimal dependencies

Installation

  1. Pull the package with:
go get github.com/Laelapa/guarddoggo
  1. then import it in your code with:
import "github.com/Laelapa/guarddoggo"

🐾 Quick Start

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
}

TODOs

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

About

A faithful Go package for JWT and refresh token management. Keeps your auth tokens on a tight leash.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages