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

+87
View File
@@ -0,0 +1,87 @@
package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// IDPAdminView lists the platform identity providers for admins.
type IDPAdminView struct {
Providers []IDPRow
// CallbackURL is what to register at the provider.
CallbackURL string
}
// IDPRow is a platform identity provider; its secret is never shown.
type IDPRow struct {
ID, Kind, Name, Issuer, ClientID string
SecretSet, AllowSignup, Enabled bool
}
templ idpFields(r IDPRow, isNew bool) {
if isNew {
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "idp.kind") }</span>
<select name="kind" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="oidc">{ i18n.T(ctx, "idp.kind_oidc") }</option>
<option value="github">GitHub</option>
</select>
</label>
} else {
<input type="hidden" name="kind" value={ r.Kind }/>
}
@valueField(i18n.T(ctx, "sso.field.name"), "name", r.Name, "Google", true)
@valueField(i18n.T(ctx, "idp.issuer"), "issuer", r.Issuer, "https://accounts.google.com", false)
@valueField(i18n.T(ctx, "idp.client_id"), "client_id", r.ClientID, "", true)
@secretField(i18n.T(ctx, "idp.client_secret"), "client_secret", r.SecretSet)
@checkbox(i18n.T(ctx, "idp.allow_signup"), "allow_signup", r.AllowSignup || isNew)
@checkbox(i18n.T(ctx, "idp.enabled"), "enabled", r.Enabled || isNew)
}
templ idpSection(v IDPAdminView) {
<section id="identity-providers" class="mb-12 max-w-3xl">
@sectionHeading("idp.title")
<p class="mb-2 text-sm text-muted">{ i18n.T(ctx, "idp.intro") }</p>
<p class="mb-4 text-sm">{ i18n.T(ctx, "idp.callback") } <code class="font-mono text-xs">{ v.CallbackURL }</code></p>
if len(v.Providers) > 0 {
<ul class="mb-6 divide-y divide-rule border-y border-rule text-sm">
for _, r := range v.Providers {
<li class="py-2.5">
<div class="flex flex-wrap items-baseline gap-x-4 gap-y-1">
if r.Enabled {
@statusDot(StatusUp)
} else {
@statusDot(StatusPaused)
}
<span class="font-medium">{ r.Name }</span>
<span class="font-mono text-xs text-muted">{ r.Issuer }</span>
if r.AllowSignup {
<span class="text-xs text-muted">{ i18n.T(ctx, "idp.signup_open") }</span>
}
<button
type="button"
data-delete={ "/admin/identity-providers/" + r.ID }
data-confirm={ i18n.T(ctx, "idp.delete_confirm", "Name", r.Name) }
class="ml-auto text-muted hover:text-down"
>{ i18n.T(ctx, "regions.delete") }</button>
</div>
<details class="mt-2">
<summary class="cursor-pointer text-xs text-muted hover:text-ink">{ i18n.T(ctx, "sso.action.edit") }</summary>
<form data-api={ "/admin/identity-providers/" + r.ID } data-method="put" data-next="/admin#identity-providers" class="mt-3 max-w-sm">
@formError()
@idpFields(r, false)
@submit(i18n.T(ctx, "common.save"))
</form>
</details>
</li>
}
</ul>
}
<details>
<summary class="cursor-pointer text-sm text-muted hover:text-ink">{ i18n.T(ctx, "idp.add") }</summary>
<form data-api="/admin/identity-providers" data-next="/admin#identity-providers" class="mt-3 max-w-sm">
@formError()
<p class="mb-3 text-xs text-muted">{ i18n.T(ctx, "idp.issuer_hint") }</p>
@idpFields(IDPRow{}, true)
@submit(i18n.T(ctx, "idp.add"))
</form>
</details>
</section>
}