jwks

package
v4.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidURL returned when input url has invalid format.
	ErrInvalidURL = errors.New("jwks: invalid url value or format")
	// ErrInvalidNumRetries returned when number of retries is zero.
	ErrInvalidNumRetries = errors.New("jwks: invalid number of retries")
	// ErrKeyIDNotProvided returned when input kid is not present.
	ErrKeyIDNotProvided = errors.New("jwks: kid is not provided")
	// ErrPublicKeyNotFound returned when no public key is found.
	ErrPublicKeyNotFound = errors.New("jwks: public key not found")
)
View Source
var (
	// ErrCacheNotFound returned when cache value not found.
	ErrCacheNotFound = errors.New("cache: value not found")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Add(key *JWK) error
	Get(kid string) (*JWK, error)
	Len() (int, error)
}

Cache works with cache layer.

type JWK

type JWK = jwk.JWK

JWK represents an unparsed JSON Web Key (JWK) in its wire format.

type Manager

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

Manager fetches and returns JWK from public source.

func NewManager

func NewManager(rawURL string, opts ...Option) (*Manager, error)

NewManager returns a new instance of Manager.

func (*Manager) FetchKey

func (m *Manager) FetchKey(ctx context.Context, kid string, tokenVars map[string]any) (*JWK, error)

FetchKey fetches JWKS from public source or cache.

type Option

type Option func(m *Manager)

Option is used for configuring key manager.

func WithCache

func WithCache(c Cache) Option

WithCache sets custom cache. Default is TTLCache.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets custom http client. By default client with 1 sec timeout used.

func WithMaxRetries

func WithMaxRetries(n uint) Option

WithMaxRetries defines max retries count if request has been failed. Default is 2.

func WithUseCache

func WithUseCache(flag bool) Option

WithUseCache defines useCache option. Default is true.

type TTLCache

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

TTLCache is a TTL bases in-memory cache.

func NewTTLCache

func NewTTLCache(ttl time.Duration) *TTLCache

NewTTLCache returns a new instance of ttl cache.

func (*TTLCache) Add

func (tc *TTLCache) Add(key *JWK) error

Add item into cache.

func (*TTLCache) Get

func (tc *TTLCache) Get(kid string) (*JWK, error)

Get item by key.

func (*TTLCache) Len

func (tc *TTLCache) Len() (int, error)

Len returns current size of cache.

func (*TTLCache) Stop

func (tc *TTLCache) Stop() error

Stop stops TTL cache.

Jump to

Keyboard shortcuts

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