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 ¶
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.
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 ¶
Client is the credential the resource introspects tokens with (RFC 7662 § 2.1): a confidential client of the provider.
func ReadClientFile ¶
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.