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

+43 -11
View File
@@ -5,15 +5,36 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
templ Login(p Page, signupAllowed bool, next string) {
// IDPButton is a platform identity provider to sign in with.
type IDPButton struct {
URL, Name, Kind string
}
templ idpButtons(providers []IDPButton, labelID string) {
if len(providers) > 0 {
<div class="mb-8 grid gap-2">
for _, pr := range providers {
<a href={ templ.SafeURL(pr.URL) } class="block border border-ink px-3 py-2 text-center text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, labelID, "Name", pr.Name) }</a>
}
</div>
<p class="mb-6 text-center text-xs uppercase tracking-wider text-muted">{ i18n.T(ctx, "auth.or") }</p>
}
}
// Login signs in; mfa starts at the second factor, after a provider
// confirmed who it is.
templ Login(p Page, signupAllowed bool, next string, providers []IDPButton, mfa bool) {
@authShell(p) {
if !mfa {
@idpButtons(providers, "auth.sso.continue_with")
}
<form data-api="/auth/login" data-next={ next }>
@formError()
<div data-step="password">
<div data-step="password" hidden?={ mfa }>
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
</div>
<div data-step="totp" hidden>
<div data-step="totp" hidden?={ !mfa }>
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "auth.login.totp_hint") }</p>
@field(i18n.T(ctx, "auth.field.code"), "code", "text", "one-time-code", false)
</div>
@@ -43,15 +64,26 @@ templ Login(p Page, signupAllowed bool, next string) {
}
}
templ Signup(p Page) {
// Signup offers the providers people may sign up through and, if email
// is set, the form for signing up with email and password.
templ Signup(p Page, providers []IDPButton, email bool) {
@authShell(p) {
<form data-api="/auth/signup" data-next="/">
@formError()
@field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false)
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true)
@submit(i18n.T(ctx, "auth.signup.submit"))
</form>
if email {
@idpButtons(providers, "auth.sso.signup_with")
<form data-api="/auth/signup" data-next="/">
@formError()
@field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false)
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true)
@submit(i18n.T(ctx, "auth.signup.submit"))
</form>
} else {
<div class="grid gap-2">
for _, pr := range providers {
<a href={ templ.SafeURL(pr.URL) } class="block border border-ink px-3 py-2 text-center text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "auth.sso.signup_with", "Name", pr.Name) }</a>
}
</div>
}
<p class="mt-8 text-sm text-muted"><a class="text-ink underline underline-offset-2" href="/login">{ i18n.T(ctx, "auth.signup.to_login") }</a></p>
}
}