mjwt

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: LGPL-3.0 Imports: 18 Imported by: 17

README

MJWT

A simple wrapper for JWT. Contains an AccessToken and RefreshToken model.

Documentation

Index

Constants

View Source
const PemExt = ".pem"
View Source
const PrivatePemExt = PrivateStr + PemExt
View Source
const PrivateStr = ".private"
View Source
const PublicPemExt = PublicStr + PemExt
View Source
const PublicStr = ".public"

Variables

View Source
var ErrClaimTypeMismatch = errors.New("claim type mismatch")
View Source
var ErrMissingKeyPair = errors.New("missing key pair")
View Source
var ErrMissingPrivateKey = errors.New("missing private key")
View Source
var ErrMissingPublicKey = errors.New("missing public key")

Functions

func WriteJwkSetJson added in v0.4.0

func WriteJwkSetJson(w io.Writer, issuers []*Issuer) error

Types

type BaseTypeClaims

type BaseTypeClaims[T Claims] struct {
	jwt.RegisteredClaims
	ClaimType string
	Claims    T
}

BaseTypeClaims is a wrapper for combining the jwt.RegisteredClaims with a ClaimType and generic Claims data

func ExtractClaims

func ExtractClaims[T Claims](ks *KeyStore, token string) (*jwt.Token, BaseTypeClaims[T], error)

ExtractClaims uses a Verifier to validate the MJWT token and returns the parsed token and BaseTypeClaims

func (*BaseTypeClaims[T]) InternalClaimType

func (b *BaseTypeClaims[T]) InternalClaimType() string

InternalClaimType returns the Type of the generic claim struct

func (*BaseTypeClaims[T]) MarshalJSON

func (b *BaseTypeClaims[T]) MarshalJSON() ([]byte, error)

MarshalJSON converts the internalBaseTypeClaims and generic claim struct into a serialized JSON byte array

func (*BaseTypeClaims[T]) UnmarshalJSON

func (b *BaseTypeClaims[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON reads the internalBaseTypeClaims and generic claim struct from a serialized JSON byte array

func (*BaseTypeClaims[T]) Valid

func (b *BaseTypeClaims[T]) Valid() error

Valid checks the InternalClaimType matches and the type claim type

type Claims

type Claims interface {
	jwt.Claims
	Type() string
}

Claims is a wrapper for jwt.Claims and adds a Type method to name internal claim structs

type EmptyClaims added in v0.4.0

type EmptyClaims struct{}

EmptyClaims contains no claims

func (EmptyClaims) Type added in v0.4.0

func (e EmptyClaims) Type() string

func (EmptyClaims) Valid added in v0.4.0

func (e EmptyClaims) Valid() error

type Issuer added in v0.4.0

type Issuer struct {
	// contains filtered or unexported fields
}

func NewIssuer added in v0.4.0

func NewIssuer(name, kid string, signing jwt.SigningMethod) (*Issuer, error)

func NewIssuerWithKeyStore added in v0.4.0

func NewIssuerWithKeyStore(name, kid string, signing jwt.SigningMethod, keystore *KeyStore) (*Issuer, error)

func (*Issuer) GenerateJwt added in v0.4.0

func (i *Issuer) GenerateJwt(sub, id string, aud jwt.ClaimStrings, dur time.Duration, claims Claims) (string, error)

func (*Issuer) KeyStore added in v0.4.0

func (i *Issuer) KeyStore() *KeyStore

func (*Issuer) PrivateKey added in v0.4.0

func (i *Issuer) PrivateKey() (*rsa.PrivateKey, error)

func (*Issuer) SignJwt added in v0.4.0

func (i *Issuer) SignJwt(wrapped jwt.Claims) (string, error)

type KeyStore added in v0.3.0

type KeyStore struct {
	// contains filtered or unexported fields
}

func NewKeyStore added in v0.4.0

func NewKeyStore() *KeyStore

func NewKeyStoreFromDir added in v0.4.0

func NewKeyStoreFromDir(dir afero.Fs) (*KeyStore, error)

func NewKeyStoreWithDir added in v0.4.0

func NewKeyStoreWithDir(dir afero.Fs) *KeyStore

func (*KeyStore) ClearKeys added in v0.3.0

func (k *KeyStore) ClearKeys()

func (*KeyStore) GetPrivateKey added in v0.4.0

func (k *KeyStore) GetPrivateKey(kid string) (*rsa.PrivateKey, error)

func (*KeyStore) GetPublicKey added in v0.4.0

func (k *KeyStore) GetPublicKey(kid string) (*rsa.PublicKey, error)

func (*KeyStore) HasPrivateKey added in v0.4.0

func (k *KeyStore) HasPrivateKey(kid string) bool

func (*KeyStore) HasPublicKey added in v0.4.0

func (k *KeyStore) HasPublicKey(kid string) bool

func (*KeyStore) ListKeys added in v0.3.0

func (k *KeyStore) ListKeys() []string

func (*KeyStore) LoadPrivateKey added in v0.4.0

func (k *KeyStore) LoadPrivateKey(kid string, key *rsa.PrivateKey)

func (*KeyStore) LoadPublicKey added in v0.4.0

func (k *KeyStore) LoadPublicKey(kid string, key *rsa.PublicKey)

func (*KeyStore) RemoveKey added in v0.3.0

func (k *KeyStore) RemoveKey(kid string)

func (*KeyStore) SaveKeys added in v0.4.0

func (k *KeyStore) SaveKeys() error

func (*KeyStore) SaveSingleKey added in v0.4.0

func (k *KeyStore) SaveSingleKey(kid string) error

func (*KeyStore) VerifyJwt added in v0.4.0

func (k *KeyStore) VerifyJwt(token string, claims baseTypeClaim) (*jwt.Token, error)

Directories

Path Synopsis
cmd
mjwt command

Jump to

Keyboard shortcuts

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