feat: sign up and sign in with platform identity providers
ci / build (pull_request) Successful in 5m13s
ci / lint (pull_request) Successful in 5m45s
ci / image (pull_request) Successful in 6m20s
ci / test (pull_request) Successful in 11m46s

Platform admins register identity providers for the whole installation:
any OpenID Connect provider, checked by discovery, and GitHub or GitHub
Enterprise through OAuth, which reads the primary email GitHub verified.
Sign-in pages offer them; the sign-up page offers those open to sign-up,
also where email sign-up is closed for lack of a mail server.

Accounts are reached only through identities stored by subject. A new
identity signs up only with an email the provider confirmed, within the
per-address limit and sign-up mode, and never takes over an existing
account, including through an alias of its address: its owner links
the provider in the security settings. The account's TOTP still applies
after the provider. Unlinking refuses to remove the last way to sign in,
and removing a provider refuses while accounts depend on it.

The test browser takes the CSRF token from pages, as the console does.

Closes #114

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-23 01:26:14 +01:00
1 parent 1ad68e2e87
commit fe5c4fb24c
26 files changed
+2710 -351

No files matched your search

+16 -1
View File
@@ -16,8 +16,10 @@ import (
"golang.org/x/oauth2"
)
// Provider is one organization's IdP registration.
// Provider is an IdP registration, of an organization or the platform.
type Provider struct {
// Kind is empty for OpenID Connect or GitHub.
Kind string
Issuer string
ClientID string
ClientSecret string
@@ -91,6 +93,9 @@ func (c *Client) ValidateIssuer(ctx context.Context, issuer string) error {
return err
}
// CheckURL checks that a server URL may be used, without contacting it.
func (c *Client) CheckURL(issuer string) error { return c.checkIssuer(issuer) }
func (c *Client) checkIssuer(issuer string) error {
u, err := url.Parse(issuer)
if err != nil || u.Host == "" || u.RawQuery != "" || u.Fragment != "" || u.User != nil {
@@ -144,6 +149,9 @@ func (c *Client) AuthURL(ctx context.Context, p Provider, f Flow) (string, error
if err := c.checkIssuer(p.Issuer); err != nil {
return "", err
}
if p.Kind == GitHub {
return c.githubOAuth(p).AuthCodeURL(f.State, oauth2.S256ChallengeOption(f.Verifier)), nil
}
op, err := c.discover(ctx, p.Issuer)
if err != nil {
return "", err
@@ -157,6 +165,13 @@ func (c *Client) AuthURL(ctx context.Context, p Provider, f Flow) (string, error
// Exchange redeems the authorization code and verifies the ID token's
// signature, issuer, audience, expiry and nonce.
func (c *Client) Exchange(ctx context.Context, p Provider, f Flow, code string) (Claims, error) {
if p.Kind == GitHub {
tok, err := c.githubOAuth(p).Exchange(oidc.ClientContext(ctx, c.http), code, oauth2.VerifierOption(f.Verifier))
if err != nil {
return Claims{}, fmt.Errorf("sso: code exchange: %w", err)
}
return c.githubClaims(ctx, p, tok)
}
op, err := c.discover(ctx, p.Issuer)
if err != nil {
return Claims{}, err