oidc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 20 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 is the client side of OpenID Connect sign-in: provider discovery, the authorization code flow with PKCE, and ID token verification (signature through the provider's JWKS, issuer, audience, expiry and nonce). It has no state beyond a key cache and knows nothing about vx people.

Index

Constants

View Source
const Skew = 2 * time.Minute

Skew is how much clock difference expiry checks allow.

Variables

View Source
var (
	ErrMalformed   = errors.New("the ID token is malformed")
	ErrAlgorithm   = errors.New("the ID token uses a signing algorithm vx does not accept")
	ErrUnknownKey  = errors.New("the ID token is signed with a key the provider does not publish")
	ErrSignature   = errors.New("the ID token's signature does not verify")
	ErrIssuer      = errors.New("the ID token comes from another issuer")
	ErrAudience    = errors.New("the ID token is for another client")
	ErrExpired     = errors.New("the ID token has expired")
	ErrNotYetValid = errors.New("the ID token is not valid yet")
	ErrNonce       = errors.New("the ID token's nonce does not match this sign-in")
	ErrNoSubject   = errors.New("the ID token names no subject")
)

Verification errors, so callers and tests can tell them apart.

Functions

func AuthorizeURL

func AuthorizeURL(m Metadata, clientID, redirectURI, state, nonce, challenge string) string

AuthorizeURL is where the browser goes to sign in: the code flow with PKCE (S256), the openid, email and profile scopes, state and nonce.

func Challenge

func Challenge(verifier string) string

Challenge is the S256 PKCE challenge of a verifier.

func CheckIssuerURL

func CheckIssuerURL(issuer string) error

CheckIssuerURL says what is wrong with an issuer URL: it must be https, except on localhost for development.

func NormalizeIssuer

func NormalizeIssuer(issuer string) string

NormalizeIssuer trims spaces and a trailing slash.

Types

type Claims

type Claims struct {
	Issuer        string
	Subject       string
	Audience      []string
	Expiry        time.Time
	IssuedAt      time.Time
	Nonce         string
	Email         string
	EmailVerified *bool // nil when the provider does not say
	Name          string
}

Claims are the ID token claims vx reads.

type Client

type Client struct {
	HTTP *http.Client
	// Now is the clock for expiry checks; nil: time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Client talks to providers. The zero value works, with a 10 second timeout.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context, issuer string) (Metadata, error)

Discover reads the provider's discovery document, cached for an hour. The document must name the same issuer.

func (*Client) Exchange

func (c *Client) Exchange(ctx context.Context, m Metadata, clientID, clientSecret, code, redirectURI, verifier string) (string, error)

Exchange trades an authorization code for the provider's ID token, authenticating with the client secret (HTTP basic unless the provider only takes it in the form).

func (*Client) Verify

func (c *Client) Verify(ctx context.Context, m Metadata, raw string, want Expected) (Claims, error)

Verify checks an ID token: its signature against the provider's JWKS (fetched again when it names a key vx has not seen, so key rotation works), issuer, audience (and azp when there are several), expiry, issued-at and nonce.

type Expected

type Expected struct {
	Issuer   string
	ClientID string
	Nonce    string
}

Expected is what an ID token must say.

type Metadata

type Metadata struct {
	Issuer                string   `json:"issuer"`
	AuthorizationEndpoint string   `json:"authorization_endpoint"`
	TokenEndpoint         string   `json:"token_endpoint"`
	JWKSURI               string   `json:"jwks_uri"`
	TokenAuthMethods      []string `json:"token_endpoint_auth_methods_supported"`
	SigningAlgs           []string `json:"id_token_signing_alg_values_supported"`
}

Metadata is the part of a provider's discovery document vx uses.

type ProviderError

type ProviderError struct {
	Code, Description string
}

ProviderError is an error answer of the token endpoint.

func (*ProviderError) Error

func (e *ProviderError) Error() string

Directories

Path Synopsis
Package oidctest is a fake OpenID Connect provider for tests: discovery, JWKS, an authorize endpoint that signs the configured user in at once, and a token endpoint that checks the client secret and PKCE and issues RS256 ID tokens.
Package oidctest is a fake OpenID Connect provider for tests: discovery, JWKS, an authorize endpoint that signs the configured user in at once, and a token endpoint that checks the client secret and PKCE and issues RS256 ID tokens.

Jump to

Keyboard shortcuts

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