jwt

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoJWKAvailable       = fmt.Errorf("no JWKs (certs or public keys) available")
	ErrNoMatchingJWKFound   = fmt.Errorf("no JWK with mathing KeyId found")
	ErrUnknownKeyType       = fmt.Errorf("JWK key of unknown type")
	ErrFailedToParseCertFn  = func(kid string, err error) error { return fmt.Errorf("error decoding certificate %q: %w", kid, err) }
	ErrUnsupportedCertChain = fmt.Errorf("JWK certificate chain unsupported")
)
View Source
var ErrInvalidJWTForm = fmt.Errorf("auth token not in JWT format")
View Source
var ErrJWTExpired = fmt.Errorf("jwt has expired")

Functions

func FetchX09SignCert

func FetchX09SignCert(keys JSONWebKeySet, kid string) (string, error)

func GetUsernameFromPayload

func GetUsernameFromPayload(jwt string) (string, error)

func ParseX09AsPublicKey

func ParseX09AsPublicKey(key, kid string) (any, *time.Time, error)

func VerifyJWT

func VerifyJWT(jwt string, certs JSONWebKeySet) (bool, error)

Verify whether a JSON Web Token is valid. Takes the token in form of a string and a set of JSON Web Keys (public keys/certs) as input.

Types

type JSONWebKey

type JSONWebKey struct {
	KeyId     string   `json:"kid"`
	X509Certs []string `json:"x5c"`
}

type JSONWebKeySet

type JSONWebKeySet map[string]JSONWebKey

func GetJSONKeyWebSet

func GetJSONKeyWebSet(endpoint string) (jwks JSONWebKeySet, err error)

type JWTHeader

type JWTHeader struct {
	Kid       string `json:"kid"`
	Algorithm string `json:"alg"`
}

type JWTPayload

type JWTPayload struct {
	Username string `json:"preferred_username,omitempty"`
	Expires  int64  `json:"exp"` // UNIX timestamp
}

Jump to

Keyboard shortcuts

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