oidc

package
v0.9.13 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 19 Imported by: 1 module, 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 verifies the ID tokens of OpenID Connect providers: the signature against the provider's published keys (cached), issuer, audience, expiry and nonce. It knows nothing of users or sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IssuerProblem

func IssuerProblem(issuer string, dev bool) string

IssuerProblem says what is wrong with an issuer URL, or "" when it is fine: https (http only in development), a host, and no credentials, query or fragment.

Types

type Claims

type Claims struct {
	// Issuer is the issuer that vouched for the subject, as the token states it (Google's older
	// form without the scheme is written with it).
	Issuer string
	// Subject identifies the person for the provider: sub, or for Microsoft the tenant
	// and object ids, so the same person in two tenants is two identities.
	Subject       string
	Email         string
	EmailVerified bool
	Name          string
	GivenName     string
	FamilyName    string
	Picture       string
	// Audience is the client id the token was issued to (the web client's, or a native app's).
	Audience string
	// HostedDomain is Google's hd (the Workspace domain of the account; empty for a personal
	// account) and Tenant Microsoft's tid, as the verified token states them.
	HostedDomain string
	Tenant       string
	// Username is Microsoft's preferred_username (the account's user principal name, lower case):
	// its domain is one the tenant has verified, unlike the address in the email claim, which the
	// tenant's administrator sets freely.
	Username string
}

Claims are what backd takes from a verified ID token.

type Discoverer

type Discoverer struct {
	// HTTP reaches the issuers: safehttp.NewClient(…) in production.
	HTTP *http.Client
	// Now is the clock; time.Now when nil.
	Now func() time.Time
	// Dev allows http issuers and endpoints (BACKD_DEV); otherwise https only.
	Dev bool
	// contains filtered or unexported fields
}

Discoverer reads and caches the discovery documents of generic OpenID Connect providers (<issuer>/.well-known/openid-configuration). The zero value needs HTTP set.

func (*Discoverer) Discover

func (d *Discoverer) Discover(ctx context.Context, issuer string, private bool) (Document, error)

Discover returns the provider's endpoints. The issuer's host is the only one reached to read the document; the endpoints it names must be on the issuer's registered domain, or the provider is refused (a document must not send backd to a host the operator did not name).

type Document

type Document struct {
	Issuer        string
	Authorization string
	Token         string
	JWKS          string
	// Hosts are the issuer's host and the endpoints' hosts, which share its registered domain.
	Hosts []string
}

Document is what a provider's discovery document says that backd uses.

type Verifier

type Verifier struct {
	// HTTP reaches the providers' key endpoints: safehttp.NewClient(…) in production.
	HTTP *http.Client
	// Now is the clock; time.Now when nil.
	Now func() time.Time
	// contains filtered or unexported fields
}

Verifier checks ID tokens. The zero value needs HTTP set.

func (*Verifier) Subject

func (s *Verifier) Subject(ctx context.Context, p sso.Provider, idToken string, native bool) (subject, audience string, err error)

Subject verifies an ID token like Verify, except for the nonce (the one the code exchange gives back has none), and returns who it is for: the subject and the client id it was issued to. It is how backd checks that an authorization code and the ID token a native app sent belong to the same person.

func (*Verifier) Verify

func (s *Verifier) Verify(ctx context.Context, p sso.Provider, idToken, nonce string, native bool) (Claims, error)

Verify checks an ID token of the provider and returns what it says about the user: its signature against the provider's keys, issuer, audience (the web client's, and, when native, the mobile apps'), expiry and nonce. nonce is what the token must carry (exactly, or, when native, also as its SHA-256 in hex or base64url, as the platform sign-in SDKs put it).

Jump to

Keyboard shortcuts

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