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
- Variables
- func AuthorizeURL(m Metadata, clientID, redirectURI, state, nonce, challenge string) string
- func Challenge(verifier string) string
- func CheckIssuerURL(issuer string) error
- func NormalizeIssuer(issuer string) string
- type Claims
- type Client
- type Expected
- type Metadata
- type ProviderError
Constants ¶
const Skew = 2 * time.Minute
Skew is how much clock difference expiry checks allow.
Variables ¶
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 ¶
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 CheckIssuerURL ¶
CheckIssuerURL says what is wrong with an issuer URL: it must be https, except on localhost for development.
func NormalizeIssuer ¶
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 ¶
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).
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. |