Documentation ¶
Overview ¶
Package jwkfetch provides tools to fetch `jwk.Set`s, as well as a container to store JWKS (`jwk.Set`) locally while keeping them more-or-less up-to-date by periodically refreshing them in the background.
Index ¶
- func Fetch(ctx context.Context, u string, options ...FetchOption) (jwk.Set, error)
- func SetDefaultParser(p JWKSParser)
- type Cache
- type CacheOption
- type ErrSink
- type FetchOption
- type HTTPClient
- type JWKSParseFunc
- type JWKSParser
- type JWKSTransform
- type Option
- type PostFetchFunc
- type PostFetcher
- type RegisterOption
- type Transformer
- type Whitelist
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fetch ¶
Fetch fetches a JWK resource specified by a URL. The url must be pointing to a resource that is supported by `net/http`.
If you are using the same `jwk.Set` for long periods of time during the lifecycle of your program, and would like to periodically refresh the contents of the object with the data at the remote resource, consider using `jwkfetch.Cache`, which automatically refreshes jwk.Set objects asynchronously.
func SetDefaultParser ¶
func SetDefaultParser(p JWKSParser)
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a container that keeps track of jwk.Set object by their source URLs. The jwk.Set objects are stored in memory, and are refreshed automatically behind the scenes.
Before retrieving the jwk.Set objects, the user must pre-register the URLs they intend to use by calling `Register()`
c := jwkfetch.New(ctx) c.Register(url, options...)
Once registered, you can call `Get()` to retrieve the jwk.Set object.
All JWKS objects that are retrieved via this mechanism should be treated read-only, as they are shared among the consumers and this object.
func NewCache ¶
func NewCache(ctx context.Context, options ...CacheOption) *Cache
NewCache creates a new `jwkfetch.Cache` object.
Please refer to the documentation for `httprc.New` for more details.
func (*Cache) Get ¶
Get returns the stored JWK set (`jwk.Set`) from the cache.
Please refer to the documentation for `(httprc.Cache).Get` for more details.
func (*Cache) IsRegistered ¶
IsRegistered returns true if the given URL `u` has already been registered in the cache.
Please refer to the documentation for `(httprc.Cache).IsRegistered` for more details.
func (*Cache) Register ¶
func (c *Cache) Register(u string, options ...RegisterOption)
Register registers a URL to be managed by the cache. URLs must be registered before issuing `Get`
This method is almost identical to `(httprc.Cache).Register`, except it accepts some extra options.
Use `jwkfetch.WithParser` to configure how the JWKS should be parsed, such as passing it extra options.
Please refer to the documentation for `(httprc.Cache).Register` for more details.
func (*Cache) Unregister ¶
Unregister removes the given URL `u` from the cache.
Please refer to the documentation for `(httprc.Cache).Unregister` for more details.
type CacheOption ¶
type CacheOption interface { Option // contains filtered or unexported methods }
CacheOption desribes options that can be passed to `New()`
func WithErrSink ¶
func WithErrSink(v ErrSink) CacheOption
WithErrSink specifies the `httprc.ErrSink` object that handles errors that occurred during the cache's execution.
See the documentation in `httprc.WithErrSink` for more details.
func WithFetchWorkerCount ¶
func WithFetchWorkerCount(v int) CacheOption
WithFetchWorkerCount specifies the number of HTTP fetch workers that are spawned in the backend.
See the documentation in `httprc.WithFetchWorkerCount` for more details.
func WithRefreshWindow ¶
func WithRefreshWindow(v time.Duration) CacheOption
WithRefreshWindow specifies the interval between checks for refreshes.
See the documentation in `httprc.WithRefreshWindow` for more details.
func WithWhitelist ¶
func WithWhitelist(v Whitelist) CacheOption
WithWhitelist specifies the Whitelist object that can control which URLs can be registered to the cache.
See the documentation in `httprc.WithWhitelist` for more details.
type FetchOption ¶
type FetchOption interface { Option // contains filtered or unexported methods }
FetchOption describes options that can be passed to `Fetch()`
type HTTPClient ¶
type HTTPClient = httprc.HTTPClient
type JWKSParseFunc ¶
type JWKSParser ¶
JWKSParser describes and object that can parse a []byte payload and turn it into a `jwk.Set` object. By default `jwk.Parse` (without any options) is used, but you may specify your custom `JWKSParser` object that calls `jwk.Parse` with as many options as you wish to use.
type JWKSTransform ¶
type JWKSTransform struct {
// contains filtered or unexported fields
}
httprc.Transofmer that transforms the response into a JWKS
type PostFetchFunc ¶
PostFetchFunc is a PostFetcher based on a functon.
type PostFetcher ¶
type PostFetcher interface { // PostFetch revceives the URL and the JWKS, after a successful // fetch and parse. // // It should return a `jwk.Set`, optionally modified, to be stored // in the cache for subsequent use PostFetch(string, jwk.Set) (jwk.Set, error) }
PostFetcher is an interface for objects that want to perform operations on the `jwk.Set` that was fetched.
type RegisterOption ¶
type RegisterOption interface { Option // contains filtered or unexported methods }
RegisterOption desribes options that can be passed to `(jwkfetch.Cache).Register()`
func WithHTTPClient ¶
func WithHTTPClient(v HTTPClient) RegisterOption
WithHTTPClient specififes the HTTP Client object that should be used to fetch the resource.
See the documentation in `httprc.WithHTTPClient` for more details.
func WithMinRefreshInterval ¶
func WithMinRefreshInterval(v time.Duration) RegisterOption
WithMinRefreshInterval specifies the minimum refresh interval to be used.
See the documentation in `httprc.WithMinRefreshInterval` for more details.
func WithParser ¶
func WithParser(v JWKSParser) RegisterOption
WithParser specifies the `JWKSParser` object to be invoked to parse the remote resource. Use this option to control how a payload should be parsed, including passing extra `jwk.ParseOption`s. If unspecified, `jwk.Parse` without any options is used
func WithPostFetcher ¶
func WithPostFetcher(v PostFetcher) RegisterOption
WithPostFetcher specifies the `PostFetcher` object that gets invoked after a successful fetch and parsing of JWK set, but before it is stored in the cache.
You can modify or otherwise do anything you want to the `jwk.Set` object in this phase.
func WithRefreshInterval ¶
func WithRefreshInterval(v time.Duration) RegisterOption
WithRefreshInterval specifies the static interval between refreshes of resources controlled by `jwkfetch.Cache`.
See the documentation in `httprc.WithRefreshInterval` for more details.
type Transformer ¶
type Transformer = httprc.Transformer