Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClaimTypeMismatch = errors.New("claim type mismatch")
Functions ¶
This section is empty.
Types ¶
type BaseTypeClaims ¶
BaseTypeClaims is a wrapper for combining the jwt.RegisteredClaims with a ClaimType and generic Claims data
func ExtractClaims ¶
func ExtractClaims[T Claims](p Verifier, 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 Signer ¶
type Signer interface { Verifier GenerateJwt(sub, id string, aud jwt.ClaimStrings, dur time.Duration, claims Claims) (string, error) SignJwt(claims jwt.Claims) (string, error) Issuer() string PrivateKey() *rsa.PrivateKey }
Signer is used to generate MJWT tokens. Signer can also be used as a Verifier.
func NewMJwtSigner ¶
func NewMJwtSigner(issuer string, key *rsa.PrivateKey) Signer
NewMJwtSigner creates a new defaultMJwtSigner using the issuer name and rsa.PrivateKey
func NewMJwtSignerFromFile ¶
NewMJwtSignerFromFile creates a new defaultMJwtSigner using the path of a rsa.PrivateKey file.
func NewMJwtSignerFromFileOrCreate ¶
NewMJwtSignerFromFileOrCreate creates a new defaultMJwtSigner using the path of a rsa.PrivateKey file. If the file does not exist then the file is created and a new private key is generated.
type Verifier ¶
type Verifier interface { VerifyJwt(token string, claims baseTypeClaim) (*jwt.Token, error) PublicKey() *rsa.PublicKey }
Verifier is used to verify the validity MJWT tokens and extract the claim values.
func NewMJwtVerifier ¶
NewMJwtVerifier creates a new defaultMJwtVerifier using the rsa.PublicKey
func NewMJwtVerifierFromFile ¶
NewMJwtVerifierFromFile creates a new defaultMJwtVerifier using the path of a rsa.PublicKey file