discovery

package
v1.0.0-dev.19 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

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

View Source
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")
)
View Source
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

func LoopbackHost(host string) bool

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

func Fetch(ctx context.Context, client *http.Client, issuer string) (Document, error)

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

func Parse(issuer string, data []byte) (Document, error)

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.

func (*KeySet) Verify

func (k *KeySet) Verify(ctx context.Context, t *jws.Token) ([]byte, error)

Verify returns t's payload under the first key of the set that fits it and verifies its signature (jws.Token.Verify), refetching the set once, through the gate, on a miss. It returns jws.ErrNoKey when no key verifies after that, or ctx's error when ctx ends while it waits.

Jump to

Keyboard shortcuts

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