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 ¶
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.
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).