Categorygithub.com/TheDeveloper10/mamba
modulepackage
1.0.1
Repository: https://github.com/thedeveloper10/mamba.git
Documentation: pkg.go.dev

# README

TheDeveloper10/mamba

Package TheDeveloper10/mamba is a very basic wrapper of the package github.com/golang-jwt/jwt/v4 that adds an optional encryption and decryption functionality using AES on top of it. It makes the work with JWT much easier!

Install

With a correctly configured Go toolchain:

go get -u github.com/TheDeveloper10/[email protected]

Examples

Create a signed token with no AES encryption:

type User struct {
    ID   uint64 `json:"id"`
    Role uint   `json:"role"`
}

func main() {
	template := mamba.TokenTemplate{
		ExpiryTime: 360, // 5 minutes after issuing a token it will expire
		SigningKey: "your-signing key", // key which will be used to sign JWT 
	}

    // generate a new token using template
	token, err := mamba.NewToken[User](&template, &User{ ID: 1234, Role: 15 })
	if err != nil {
		panic(err.Error())
	}

	// print the generated JWT
	fmt.Println(token)
}

Create a signed and encrypted token that never expires:

type User struct {
    ID   uint64 `json:"id"`
    Role uint   `json:"role"`
}

func main() {
	template := mamba.TokenTemplate{
		ExpiryTime: -1, // -1 = never expire
		SigningKey: "your-signing key", // key which will be used to sign JWT 
		EncryptionKey: "your-enc-key",
	}

    // generate a new token using template
	token, err := mamba.NewToken[User](&template, &User{ ID: 1234, Role: 15 })
	if err != nil {
		panic(err.Error())
	}

	// print the generated JWT
	fmt.Println(token)
}

# Functions

Decode a JWT (`tokenString`) based on `template`.
Check whether a JWT (`tokenString`) is valid based on `template`.
Generate a new JWT with a `body` from `template`.

# Structs

No description provided by the author