Documentation
¶
Overview ¶
Package sso signs people in with an identity provider (OpenID Connect, authorization code flow with PKCE), next to passwords: Google for now.
The ID token comes straight from the provider's token endpoint, over TLS, in exchange for the code: as OpenID Connect allows in that case, its signature is not checked, its claims are (issuer, audience, expiry, nonce).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSignIn = errors.New("sign-in failed")
ErrSignIn is a sign-in the provider or its token refused.
Functions ¶
func Configure ¶
func Configure(list ...*Provider)
Configure sets the enabled providers (call at startup).
func RandomString ¶
RandomString returns n random bytes, base64url-encoded.
Types ¶
type Identity ¶
type Identity struct {
Provider string
Subject string
Email string
EmailVerified bool
Name string
// HostedDomain is the Google Workspace domain of the account, if any.
HostedDomain string
}
Identity is who signed in.
type Provider ¶
type Provider struct {
ID string
Label string
AuthURL string
TokenURL string
// Issuers are the accepted "iss" values of ID tokens.
Issuers []string
ClientID string
ClientSecret string
// AllowedDomains: people of these domains get an account on their
// first sign-in.
AllowedDomains []string
// HostedDomain: a domain is the person's only when the provider says
// so in the "hd" claim (Google Workspace), not from the email alone.
HostedDomain bool
DefaultRole string
// HTTPClient makes the token request (default http.DefaultClient).
HTTPClient *http.Client
}
Provider is an OpenID Connect identity provider.
func (*Provider) AuthCodeURL ¶
AuthCodeURL is where to send the browser to sign in.
func (*Provider) DomainAllowed ¶
DomainAllowed reports whether the identity belongs to an allowed domain: its verified email's domain, and for Google, the Workspace domain Google vouches for (a personal account with a matching email is not enough).
func (*Provider) Exchange ¶
func (p *Provider) Exchange(ctx context.Context, redirectURI, code, verifier, nonce string) (*Identity, error)
Exchange trades the code for the person's identity, checking the ID token's issuer, audience, expiry and nonce.
func (*Provider) OwnsEmail ¶
OwnsEmail reports whether the provider vouches that the person holds their email address now. For Google: a Workspace account of the address's domain (hd), or a Gmail address. A consumer Google account created with another address keeps it "verified" even after the address changes hands, so it proves nothing about that address.