Documentation ¶
Index ¶
- Variables
- type Cache
- type CacheMap
- type LoggerContract
- type MapOption
- func MapHeadroom(headroom time.Duration) MapOption
- func MapLogger(logger LoggerContract) MapOption
- func MapName(name string) MapOption
- func MapParseOptions(parseOptions ...jwt.ParseOption) MapOption
- func MapRejectUnparsable(rejectUnparsable bool) MapOption
- func MapTokenFunction(tokenFunc func(ctx context.Context, key string) (string, error)) MapOption
- type Option
- func Headroom(headroom time.Duration) Option
- func Logger(logger LoggerContract) Option
- func Name(name string) Option
- func ParseOptions(parseOptions ...jwt.ParseOption) Option
- func RejectUnparsable(rejectUnparsable bool) Option
- func TokenFunction(tokenFunc func(ctx context.Context) (string, error)) Option
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotImplemented is the default behavior for the cache, if the // token function is not supplied. ErrNotImplemented = errors.New("not implemented") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a simple caching implementation to reuse JWTs till they expire.
type CacheMap ¶
type CacheMap struct {
// contains filtered or unexported fields
}
CacheMap is a mapped implementation of Cache, which allows storing JWTs by a key (for example a tenant UUID). As a bonus, the map is concurrency safe.
func NewCacheMap ¶
NewCacheMap returns a new mapped JWT cache.
func (*CacheMap) EnsureToken ¶
EnsureToken returns either the cached token if existing and still valid, or calls the internal token function to fetch a new token. If an error occurs in the latter case, it is passed trough.
type LoggerContract ¶ added in v1.2.0
type LoggerContract interface { Infof(format string, args ...interface{}) Debugf(format string, args ...interface{}) }
LoggerContract defines the logging methods required by the cache. This allows to use different kinds of logging libraries.
type MapOption ¶
type MapOption func(*mapConfig)
MapOption represents an option for the mapped cache.
func MapHeadroom ¶
MapHeadroom sets the headroom on how much earlier the cached tokens should be considered expired. The default is 1 second.
func MapLogger ¶
func MapLogger(logger LoggerContract) MapOption
MapLogger sets the logger to be used. The default is the logrus default logger.
func MapParseOptions ¶ added in v1.6.0
func MapParseOptions(parseOptions ...jwt.ParseOption) MapOption
MapParseOptions set the parse options which are used to parse a JWT. This can be used to implement signature validation for example.
The default empty.
func MapRejectUnparsable ¶ added in v1.6.0
MapRejectUnparsable sets if the cache should reject (and return the accompanying error) token which are not parsable. Note, unparsable can mean a failed signature check.
The default is false.
type Option ¶
type Option func(*config)
Option represents an option for the cache.
func Headroom ¶
Headroom sets the headroom on how much earlier the cached token should be considered expired. The default is 1 second.
func Logger ¶
func Logger(logger LoggerContract) Option
Logger sets the logger to be used. The default is the logrus default logger.
func ParseOptions ¶ added in v1.6.0
func ParseOptions(parseOptions ...jwt.ParseOption) Option
ParseOptions set the parse options which are used to parse a JWT. This can be used to implement signature validation for example.
The default empty.
func RejectUnparsable ¶ added in v1.6.0
RejectUnparsable sets if the cache should reject (and return the accompanying error) token which are not parsable. Note, unparsable can mean a failed signature check.
The default is false.