Documentation
¶
Overview ¶
Package discovery fetches and checks an OpenID Connect provider's discovery document (OpenID Connect Discovery 1.0).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFetch is the error Fetch and NewKeySet wrap when the provider could // not be reached: a transport error, a redirect, an answer other than // 200 or a body read error other than the body cap. ErrFetch = errors.New("discovery: fetch failed") // ErrDocument is the error Parse and Fetch wrap when they refuse a // document, one past the body cap included. ErrDocument = errors.New("discovery: document refused") )
var ErrKeys = errors.New("discovery: JWK Set refused")
ErrKeys is the error NewKeySet wraps when the fetched JWK Set is refused, past the body cap included, or holds no usable key.
Functions ¶
func LoopbackHost ¶
LoopbackHost reports whether host, as url.URL.Hostname returns it, is localhost in any case or a loopback IP literal: the only hosts where http stands in for https.
Types ¶
type Document ¶
type Document struct {
AuthorizationEndpoint string
TokenEndpoint string
JWKSURI string
// Algs is the provider's set of accepted rows, distinct and never empty.
Algs []jwk.Alg
}
Document is the part of a provider's discovery document oidc uses.
func Fetch ¶
Fetch GETs issuer's document from the issuer less one terminating "/" followed by /.well-known/openid-configuration (Discovery 1.0 §4.1), with ctx, through a copy of client that follows no redirect, and parses it.
func Parse ¶
Parse checks a document fetched for issuer, which must already pass oidc's Config.Validate: its issuer is identical to issuer (Discovery 1.0 §4.3), its endpoints meet the https rule, and its id_token_signing_alg_values_supported, RS256 when absent, shares a row with package jwk's table. Every refusal wraps ErrDocument and names the field, never its value.
type KeySet ¶
type KeySet struct {
// contains filtered or unexported fields
}
KeySet is a provider's JWK Set, fetched from its jwks_uri and cached. A miss refetches, an aged set refreshes, and every refetch passes one gate and is shared by every verify that waits for it. It starts no goroutine that outlives a fetch, so it is never stopped.
func NewKeySet ¶
func NewKeySet(ctx context.Context, client *http.Client, doc Document, now func() time.Time, logger *slog.Logger) (*KeySet, error)
NewKeySet fetches doc.JWKSURI through a copy of client that follows no redirect; client's Timeout bounds every fetch. It fails with ErrFetch or ErrKeys. now is the provider's clock, which the set's age and the gate read; logger, nil meaning slog.Default() at each call, receives the WARNs for a failed refetch and for two keys of one kid that fit one of doc.Algs.