jwt

package
v0.0.0-...-dd01cb3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultIssuer is default issuer name
	DefaultIssuer = "seennit"
	// DefaultLifeTime is default life time of a token
	DefaultLifeTime = time.Hour * 24
)

Variables

View Source
var (
	// ErrInvalidToken report that the JWT token is invalid
	ErrInvalidToken = errors.New("invalid token")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	FirstName string
	LastName  string
	UserID    string
	Email     string
}

type Config

type Config struct {
	JWTSecret string `envconfig:"JWT_SECRET" default:"eudaimonia~~~"`
}

type Generator

type Generator struct {
	Config        Config
	SigningMethod jwt.SigningMethod
}

func New

func New(conf Config) *Generator

New return new instance of JWTGenerator with configuration provided via env variable

func NewWithConfig

func NewWithConfig(conf Config) *Generator

NewWithConfig return new instance from config

func (*Generator) Sign

func (g *Generator) Sign(claims Claims) (string, error)

Sign generate JWT token base on the given claims

func (*Generator) Verify

func (g *Generator) Verify(tokenString string) (*Claims, error)

Verify verify if the given token is valid

type SignVerifier

type SignVerifier interface {
	Signer
	Verifier
}

type Signer

type Signer interface {
	Sign(claims Claims) (string, error)
}

type StandardClaims

type StandardClaims = jwt.StandardClaims

type Verifier

type Verifier interface {
	Verify(string) (*Claims, error)
}

Jump to

Keyboard shortcuts

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