parser

package
v0.0.0-...-a6f3d4c Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeysNotReceived        = errors.New("no keys were received")
	ErrKeySetNotFound         = errors.New("key set not found")
	ErrRefreshFuncNotProvided = errors.New("no refreshFunc was provided to refresh the keyset")
)

Functions

This section is empty.

Types

type JWTParser

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

func NewParser

func NewParser(issuer string, refreshFunc RefreshFunc, options ...Option) (*JWTParser, error)

NewParser returns a new instance or a non-nil error if provided RefreshFunc is nil. If no Clock is provided time.Now() is used by default. If no logger is provided then logging is disabled by default.

Make sure to invoke Run() before verifying tokens to start fetching keysets.

func (*JWTParser) EventHandlers

func (parser *JWTParser) EventHandlers() map[event.EventType][]event.Handler

func (*JWTParser) ParseToken

func (parser *JWTParser) ParseToken(s string) (entity.Token, error)

ParseToken returns a non-nil error if the token is expired, signature is invalid or any of the token's claims are invalid. Eg. token was issued in the future or specified 'kid' does not exist.

Note that if the keyset expires, this method will not wait for a new keyset to be fetched and instead it will return an error and it will continue to do so until an updated keyset is successfully retrieved.

func (*JWTParser) Run

func (parser *JWTParser) Run(ctx context.Context)

Run starts up the parser to refresh its keySet automatically using its RefreshFunc. This function will block until provided context is cancelled or the parser fails to fetch a new keyset.

type Key

type Key struct {
	Id        string
	Algorithm string
	Type      string
	Raw       crypto.PublicKey
}

Key is a struct for data necessary to register a key in a keyset.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithClock

func WithClock(clock jwt.Clock) Option

func WithLogger

func WithLogger(logger logging.Logger) Option

type RefreshFunc

type RefreshFunc func(ctx context.Context) ([]Key, error)

func DefaultRefreshFunc

func DefaultRefreshFunc(authClient pb.AuthServiceClient, tracer trace.Tracer) RefreshFunc

DefaultRefreshFunc returns a callback that uses the auth service as the keyset source and fetches the keyset using provided gRPC client. Tracing is disabled if no tracer is provided.

Jump to

Keyboard shortcuts

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