token

package
v0.0.0-...-250543c Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey = errors.New("invalid key length, must be 32 bytes")
)

Functions

This section is empty.

Types

type DataWithClaims

type DataWithClaims interface {
	GetClaims() *jwt.Claims
}

DataWithClaims holds user data with jwt.Claims

type Decoder

type Decoder interface {
	Decode(string, DataWithClaims, ...DecoderOpts) error
}

Decoder decodes a token into DataWithClaims

func MustNewDecoder

func MustNewDecoder(key []byte, opts ...DecoderOpts) Decoder

MustNewDecoder returns a new JWE decoder, panics on error

func NewDecoder

func NewDecoder(key []byte, opts ...DecoderOpts) (Decoder, error)

NewDecoder returns a new JWE decoder

type DecoderOpts

type DecoderOpts func(*jwt.Expected)

DecoderOpts represents options applied to each token

func DecoderWithIssuer

func DecoderWithIssuer(issuer string) DecoderOpts

DecoderWithIssuer will expect Issuer to match

func DecoderWithSubject

func DecoderWithSubject(subject string) DecoderOpts

DecoderWithSubject will expect Subject to match

func DecoderWithTime

func DecoderWithTime() DecoderOpts

DecoderWithTime will expect claim to be valid in current time

type EmbedJWTClaims

type EmbedJWTClaims struct {
	jwt.Claims
}

EmbedJWTClaims contains jwt.Claims Embed this in user structures to use with Encoder and Decoder interfaces

func (*EmbedJWTClaims) GetClaims

func (e *EmbedJWTClaims) GetClaims() *jwt.Claims

GetClaims returns the embedded jwt.Claims

type Encoder

type Encoder interface {
	Encode(DataWithClaims, ...EncoderOpts) (string, error)
}

Encoder encodes DataWithClaims into a token

func MustNewEncoder

func MustNewEncoder(key []byte, opts ...EncoderOpts) Encoder

MustNewEncoder returns a JWE encoder panics on wrong key length

func NewEncoder

func NewEncoder(key []byte, opts ...EncoderOpts) (Encoder, error)

NewEncoder returns a JWE encoder expects a 16, 24 or 32 byte length key

type EncoderOpts

type EncoderOpts func(*jwt.Claims)

EncoderOpts represents options applied to each token

func EncoderWithAge

func EncoderWithAge(age time.Duration) EncoderOpts

EncoderWithAge will set expiry according to current time and given duration

func EncoderWithIssuer

func EncoderWithIssuer(issuer string) EncoderOpts

EncoderWithIssuer will set Issuer

func EncoderWithSubject

func EncoderWithSubject(subject string) EncoderOpts

EncoderWithSubject will set Issuer

Jump to

Keyboard shortcuts

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