oidc

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package oidc authenticates the access tokens an OpenID provider issues (RFC 9068, OpenID Connect Discovery 1.0) as one member of a guard.Chain.

Index

Constants

View Source
const DefaultClockSkew = 30 * time.Second

DefaultClockSkew is how far a token's exp and nbf may disagree with this clock when Config.ClockSkew is zero.

View Source
const Source = "oidc"

Source is the Principal.Source of a token the provider issued.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

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

Authenticator verifies the provider's JWTs (and, when configured, has it introspect its opaque tokens); build one with New.

func New

func New(cfg Config) (*Authenticator, error)

New prepares the authenticator; the provider's discovery document is read when the first token arrives (every token Unavailable until it is), so a provider that is down stops nobody starting.

func (*Authenticator) Metadata

func (a *Authenticator) Metadata() guard.ResourceMetadata

Metadata names the issuer as the authorization server and the configured scopes (RFC 9728 § 2).

func (*Authenticator) Verify

func (a *Authenticator) Verify(ctx context.Context, authorization string, _ *http.Request) (guard.Principal, guard.Refusal)

Verify accepts a JWT the provider signed for this audience within its validity (RFC 9068 § 4); a token that is not a JWT is introspected, or NothingPresented.

type Client

type Client struct {
	ID     string `json:"client_id"`
	Secret string `json:"client_secret"`
}

Client is the credential the resource introspects tokens with (RFC 7662 § 2.1): a confidential client of the provider.

func ReadClientFile

func ReadClientFile(path string) (Client, error)

ReadClientFile reads a Client from the JSON file at path, an object with client_id and client_secret.

type Config

type Config struct {
	// Issuer is the provider's issuer identifier (Discovery § 3; https, or
	// loopback): <Issuer>/.well-known/openid-configuration is read at New.
	Issuer string
	// Audience is the value a token's aud must hold (RFC 9068 § 4): the MCP
	// resource URL (RFC 8707 § 2).
	Audience string
	// ScopeClaim names the claim the scopes are read from; "" reads the
	// space-separated scope claim (RFC 9068 § 2.2.3), then the scp array.
	ScopeClaim string
	// Roles maps a value of the roles claim to the scopes it grants.
	Roles map[string][]string
	// Scopes are what the resource advertises as scopes_supported.
	Scopes []string
	// ClockSkew is tolerated on exp and nbf; zero is DefaultClockSkew.
	ClockSkew time.Duration
	// Introspect is the RFC 7662 endpoint a token that is not a JWT is sent
	// to (https, or loopback); "" passes such tokens on to the next authenticator.
	Introspect string
	// Client authenticates the introspection requests (RFC 7662 § 2.1).
	Client Client
	// HTTPClient reaches the provider; nil is http.DefaultClient.
	HTTPClient *http.Client
	// Now is the clock; nil is time.Now.
	Now func() time.Time
}

Config is how an Authenticator is built.

func (Config) Check

func (cfg Config) Check() error

Check reports what makes cfg unusable before any provider is contacted: no issuer or audience, a cleartext URL off loopback, half an introspection pair.

Jump to

Keyboard shortcuts

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