jwt

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxTimeDifferenceBetweenNodes = 30 * time.Second

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 NewRegisteredClaims added in v0.23.0

func NewRegisteredClaims(opts ...RegisteredClaimsOption) jwt.RegisteredClaims

NewRegisteredClaims returns a new jwt.RegisteredClaims with the IssuedAt and NotBefore fields set to the current time plus the given offset. The offset can be used to account for time differences between nodes in a distributed system. If no offset option is provided, MaxTimeDifferenceBetweenNodes is used as the default.

func NewRegisteredClaimsWithLifetime added in v0.23.0

func NewRegisteredClaimsWithLifetime(lifetime time.Duration, opts ...RegisteredClaimsOption) jwt.RegisteredClaims

NewRegisteredClaimsWithLifetime returns a new jwt.RegisteredClaims with the IssuedAt and NotBefore fields set to the current time plus the given optional offset and the ExpiresAt field set to the current time plus the given lifetime.

func NewStandardClaims deprecated

func NewStandardClaims() jwt.RegisteredClaims

Deprecated: NewStandardClaims use NewRegisteredClaims instead.

func NewStandardClaimsWithLifetime deprecated

func NewStandardClaimsWithLifetime(lifetime time.Duration) jwt.RegisteredClaims

Deprecated: NewStandardClaimsWithLifetime use NewRegisteredClaimsWithLifetime instead.

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

type RegisteredClaimsOption added in v0.23.0

type RegisteredClaimsOption func(*registeredClaimsOptions)

RegisteredClaimsOption configures how RegisteredClaims are created.

func WithOffset added in v0.23.0

func WithOffset(offset time.Duration) RegisteredClaimsOption

WithOffset sets the offset to account for time differences between nodes.

Jump to

Keyboard shortcuts

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