tokenizer

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 13 Imported by: 0

README

tokenizer

A wrapper around golang-jwt to create a client which can easily create and parse regular jwt tokens or encrypted jwt tokens with different signing methods HMAC, AES, EdDSA.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNonPointerClaim = errors.New("invalid claims type, the claims must be a pointer")
View Source
var ErrTokenExpired = errors.New("token expired")

Functions

func CreateToken

func CreateToken(ctx context.Context, c Config, claims jwt.Claims) (string, error)

Create a new jwt token.

func ParseToken

func ParseToken(ctx context.Context, c Config, token string, claims jwt.Claims) error

Verify jwt token signature and deserialize the claims to the provided dst.

Types

type Config

type Config interface {
	GetSigningMethod() jwt.SigningMethod
	GetPrivateKey() any
	GetPublicKey() any
}

type EC added in v0.2.0

type EC struct {
	SigningMethod jwt.SigningMethod
	PrivateKey    *ecdsa.PrivateKey
	PublicKey     *ecdsa.PublicKey
}

EC

func NewEC added in v0.2.0

func NewEC(sm jwt.SigningMethod, privateKeyPem, publicKeyPem []byte) (*EC, error)

New ES

func (*EC) GetPrivateKey added in v0.2.0

func (h *EC) GetPrivateKey() any

func (*EC) GetPublicKey added in v0.2.0

func (h *EC) GetPublicKey() any

func (*EC) GetSigningMethod added in v0.2.0

func (h *EC) GetSigningMethod() jwt.SigningMethod

type ED

type ED struct {
	SigningMethod jwt.SigningMethod
	PrivateKey    crypto.PrivateKey
	PublicKey     crypto.PublicKey
}

ED

func NewED

func NewED(sm jwt.SigningMethod, privateKeyPem, publicKeyPem []byte) (*ED, error)

New ED configuration

func (*ED) GetPrivateKey

func (h *ED) GetPrivateKey() any

func (*ED) GetPublicKey

func (h *ED) GetPublicKey() any

func (*ED) GetSigningMethod

func (h *ED) GetSigningMethod() jwt.SigningMethod

type HMAC

type HMAC struct {
	SigningMethod jwt.SigningMethod
	SigningKey    []byte
}

HMAC

func NewHMAC

func NewHMAC(sm jwt.SigningMethod, signingKey []byte) (*HMAC, error)

New Hmac configuration

func (*HMAC) GetPrivateKey

func (h *HMAC) GetPrivateKey() any

func (*HMAC) GetPublicKey

func (h *HMAC) GetPublicKey() any

func (*HMAC) GetSigningMethod

func (h *HMAC) GetSigningMethod() jwt.SigningMethod

type RSA

type RSA struct {
	SigningMethod jwt.SigningMethod
	PrivateKey    *rsa.PrivateKey
	PublicKey     *rsa.PublicKey
}

RSA

func NewRSA

func NewRSA(sm jwt.SigningMethod, privateKeyPem, publicKeyPem []byte) (*RSA, error)

New RSA configuration

func (*RSA) GetPrivateKey

func (h *RSA) GetPrivateKey() any

func (*RSA) GetPublicKey

func (h *RSA) GetPublicKey() any

func (*RSA) GetSigningMethod

func (h *RSA) GetSigningMethod() jwt.SigningMethod

Jump to

Keyboard shortcuts

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