jwt

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxTimeDifferenceBetweenNodes = time.Second * 30

MaxTimeDifferenceBetweenNodes represents an offset that should be taken into account when creating e.g. jwt tokens with the `notBefore` flag.

Functions

func DefaultKeyFunc

func DefaultKeyFunc(key Key, deprecatedKeys map[string]Key) jwt.Keyfunc

func NewKeysFromFilenames

func NewKeysFromFilenames(publicKeyPemFilename, privateKeyPemFilename string, deprecatedPublicKeyPemFilenames []string) (Key, []Key, error)

NewKeysFromFilenames helper

func NewStandardClaims

func NewStandardClaims() jwt.StandardClaims

func NewStandardClaimsWithLifetime

func NewStandardClaimsWithLifetime(lifetime time.Duration) jwt.StandardClaims

Types

type JWT

type JWT struct {
	// key for signing
	Key Key
	// KeyFunc provider
	KeyFunc jwt.Keyfunc
	// DeprecatedKeys  e.g. due to rotation
	DeprecatedKeys map[string]Key
}

func New

func New(key Key, opts ...Option) *JWT

New returns a new JWT for the given key and optional old keys e.g. due to rotation

func (*JWT) GetSignedToken

func (j *JWT) GetSignedToken(claims jwt.Claims) (string, error)

func (*JWT) ParseWithClaims

func (j *JWT) ParseWithClaims(token string, claims jwt.Claims) (*jwt.Token, error)

type Key

type Key struct {
	// ID (required) represents the key identifier e.g. the md5 representation of the public key
	ID string
	// Public (required) rsa key
	Public *rsa.PublicKey
	// Private (optional) rsa key
	Private *rsa.PrivateKey
}

func NewDeprecatedKeysFromFilenames

func NewDeprecatedKeysFromFilenames(publicKeyPemFilenames []string) ([]Key, error)

NewDeprecatedKeysFromFilenames returns new Keys from the given file names

func NewKey

func NewKey(id string, public *rsa.PublicKey, private *rsa.PrivateKey) Key

NewKey return a new Key

func NewKeyFromFilenames

func NewKeyFromFilenames(publicKeyPemFilename, privateKeyPemFilename string) (Key, error)

NewKeyFromFilenames returns a new Key from the given file names

type Option

type Option func(*JWT)

func WithDeprecatedKeys

func WithDeprecatedKeys(v ...Key) Option

WithDeprecatedKeys middleware option

func WithKeyFun

func WithKeyFun(v jwt.Keyfunc) Option

WithKeyFun middleware option

Jump to

Keyboard shortcuts

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