jwtlib

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package jwtlib is for encapsulating github.com/dgrijalva/jwt-go any operations

As a quick start:

userID := "user1"
customPayload := map[string]interface{}{
	"userID": userID,
}
jwtLib := jwtlib.NewJWTLib(jwtlib.Config{
	Payload:      customPayload,
	SignALG:      jwtlib.HS256,
	SecretKey:    []byte("secret"),
	TokenTimeout: time.Hour,
})
token, err := jwtLib.Sign()
if err != nil {
	panic(err)
}
fmt.Println(token)

payload, err := jwtLib.Verify(token)
if err != nil {
	panic(err)
}
fmt.Println(payload)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth interface {
	Sign() (string, error)
	Verify(token string) (map[string]interface{}, error)
}

func NewJWTLib

func NewJWTLib(c Config) Auth

type Config

type Config struct {
	Payload map[string]interface{}

	SignALG      SignALG
	SecretKey    []byte
	TokenTimeout time.Duration
	// contains filtered or unexported fields
}

type JWTAuth

type JWTAuth struct {
	// contains filtered or unexported fields
}

func (*JWTAuth) Sign

func (j *JWTAuth) Sign() (string, error)

func (*JWTAuth) Verify

func (j *JWTAuth) Verify(token string) (map[string]interface{}, error)

type SignALG

type SignALG jwt.SigningMethod
var HS256 SignALG = jwt.SigningMethodHS256

Jump to

Keyboard shortcuts

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