jwt

package
v1.39.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MalformedToken            = errors.New("Token is malformed")
	InvalidNumberOfSegments   = errors.New("Token contains an invalid number of segments")
	UnavailableSigningMethod  = errors.New("Token is unverifiable, signing method is unavailable")
	UnspecifiedSigningMethod  = errors.New("Token is unverifiable, signing method is unspecified")
	TokenIsExpired            = errors.New("Token is expired")
	TokenIsNotValidYet        = errors.New("Token is not valid yet")
	TokenCouldNotBeDecoded    = errors.New("Token could not be decoded")
	SigningAlgorithmIncorrect = errors.New("Algorithm in header does not match signing algorithm")
)

Functions

func Decode

func Decode(tokenString string, secret []byte, algorithm string, claims Claimable) error

Call to get verification, claims need to be decoded either way so there's not point in just running the validation in isolation

func Encode

func Encode(claims Claimable, secret []byte, algorithm string) (string, error)

func Peek

func Peek(tokenString string, claims Claimable) error

Like Decode but no validation, don't forget to actually validate using decode

Types

type Audience added in v1.36.3

type Audience string

Audience handles JWT "aud" which can be either a string or array of strings.

func (*Audience) UnmarshalJSON added in v1.36.3

func (a *Audience) UnmarshalJSON(data []byte) error

type Claimable

type Claimable interface {
	Validate() error
	AfterNbf(int64) bool
	BeforeExp(int64) bool
	Clone() Claimable
}

type Claims

type Claims struct {
	IssuedAt       int64 `json:"iat,omitempty"`
	ExpirationTime int64 `json:"exp,omitempty"`
	NotBefore      int64 `json:"nbf,omitempty"`

	Issuer   string   `json:"iss,omitempty"`
	Subject  string   `json:"sub,omitempty"`
	Audience Audience `json:"aud,omitempty"`
	JTI      string   `json:"jti,omitempty"`

	ValidateFn func() error `json:"-" datastore:"-"`
}

func (Claims) AfterNbf

func (c Claims) AfterNbf(now int64) bool

func (Claims) BeforeExp

func (c Claims) BeforeExp(now int64) bool

func (Claims) Clone

func (c Claims) Clone() Claimable

func (Claims) JSON

func (c Claims) JSON() string

func (Claims) Validate

func (c Claims) Validate() error
type Header struct {
	Type string `json:"typ"`

	Algorithm string `json:"alg"`
}

Jump to

Keyboard shortcuts

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