jwtmanager

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 2 Imported by: 0

README

JWT Pair Manager

go get github.com/morf1lo/jwt-pair-manager

Example

package main

import (
    "time"

    "github.com/golang-jwt/jwt/v5"
    "github.com/morf1lo/jwt-pair-manager"
)

func main() {
	data := jwtmanager.GenerateJWTPairData{
		AccessMethod: jwt.SigningMethodHS256,
		AccessSecret: []byte("super_mega_ACCESS_secret"),
		AccessClaims: jwt.MapClaims{
			"id": 123,
			"role": "user",
		},
		AccessExpiry: time.Hour,
		RefreshMethod: jwt.SigningMethodHS256,
		RefreshSecret: []byte("super_mega_REFRESH_secret"),
		RefreshClaims: jwt.MapClaims{
			"id": 123,
		},
		RefreshExpiry: time.Hour * 24 * 3,
	}

    jwtPair, err := jwtmanager.GenerateJWTPair(data)
    if err != nil {
        // Handle error
    }

    fmt.Printf("Access Token: %s\n", jwtPair.AccessToken)
    fmt.Printf("Access Expires at: %v\n", jwtPair.AccessTokenExp)
    fmt.Printf("Refresh Token: %s\n", jwtPair.RefreshToken)
    fmt.Printf("Refresh Expires at: %v\n", jwtPair.RefreshTokenExp)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJWT

func DecodeJWT(tokenString string, secret []byte) (jwt.MapClaims, error)

Types

type GenerateJWTPairData

type GenerateJWTPairData struct {
	AccessMethod  jwt.SigningMethod
	AccessSecret  []byte
	AccessClaims  jwt.MapClaims
	AccessExpiry  time.Duration
	RefreshMethod jwt.SigningMethod
	RefreshSecret []byte
	RefreshClaims jwt.MapClaims
	RefreshExpiry time.Duration
}

type JWTPair

type JWTPair struct {
	AccessToken     string        `json:"access_token"`
	AccessTokenExp  time.Duration `json:"access_token_exp"`
	RefreshToken    string        `json:"refresh_token"`
	RefreshTokenExp time.Duration `json:"refresh_token_exp"`
}

func GenerateJWTPair

func GenerateJWTPair(data GenerateJWTPairData) (*JWTPair, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL