jwthelper

package
v0.0.0-...-5bb8762 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// JWTTokenSigningKey is key used to sign jtw tokens
	JWTTokenSigningKey = rndKey(32)
	// JWTTokenSigningKey set static for testing, but should be random..
	// JWTTokenDuration is how long the jwt token is valid
	JWTTokenDuration = 1 * time.Hour
)
View Source
var (
	ErrTokenExpired              = errors.New("Token has expired")
	ErrTokenInvalidData          = errors.New("Token contains invalid data")
	ErrTokenInvalidSigningMethod = errors.New("Token has an invalid signing method")
	ErrTokenConversionError      = errors.New("Token conversion error")
)

Errors returned

Functions

func Sign

func Sign(i interface{}) (string, error)

Sign turns users credentials in to a JWT token string

func Validate

func Validate(tokenStr string, i interface{}) error

Validate validates the Authorization header provided by the client, and returns the JWT token details

Types

type Credentials

type Credentials struct {
	Id     string   `json:"id"`    // user ID matching the user
	Tokens []string `json:"tk"`    // authorization tokens of the user
	Nonce  float64  `json:"nonce"` // nonce
}

JWTUserCredentials is the token given to the user

Jump to

Keyboard shortcuts

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