feat(api): let each organization sign in through its own identity provider
Owners manage OIDC providers under /settings/sso. Users start at /sso/<org>. New users can be provisioned for verified emails in allowed domains; existing accounts are never matched by email and must link their SSO sign-in while signed in. Closes #4 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
9ad5f29f1b
commit
3f21361995
19 files changed
+2731
-231
No files matched your search
@@ -0,0 +1,156 @@
|
||||
package web
|
||||
|
||||
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
|
||||
// SSOOption is one provider on the chooser page.
|
||||
type SSOOption struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
|
||||
templ SSOChooser(p Page, opts []SSOOption) {
|
||||
@authShell(p) {
|
||||
<ul class="divide-y divide-rule border-y border-rule">
|
||||
for _, o := range opts {
|
||||
<li><a href={ templ.SafeURL(o.URL) } class="block py-2.5 hover:underline">{ o.Name }</a></li>
|
||||
}
|
||||
</ul>
|
||||
<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>
|
||||
}
|
||||
}
|
||||
|
||||
// SSOProvider is a provider row on the settings page.
|
||||
type SSOProvider struct {
|
||||
ID string
|
||||
Name string
|
||||
Issuer string
|
||||
ClientID string
|
||||
HasSecret bool
|
||||
AllowedDomains string
|
||||
AutoProvision bool
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
// SSOSettings is the data of the organization SSO page.
|
||||
type SSOSettings struct {
|
||||
Providers []SSOProvider
|
||||
RedirectURL string
|
||||
LoginURL string
|
||||
}
|
||||
|
||||
templ SSOSettingsPage(p Page, me Me, s SSOSettings) {
|
||||
@consoleShell(p, me) {
|
||||
<h1 class="mb-2 text-lg font-semibold">{ i18n.T(ctx, "sso.settings.title") }</h1>
|
||||
<p class="mb-8 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "sso.settings.intro") }</p>
|
||||
<dl class="mb-10 grid max-w-2xl grid-cols-[max-content_1fr] gap-x-6 gap-y-2 text-sm">
|
||||
<dt class="text-muted">{ i18n.T(ctx, "sso.settings.redirect_url") }</dt>
|
||||
<dd class="break-all font-mono text-xs leading-5">{ s.RedirectURL }</dd>
|
||||
<dt class="text-muted">{ i18n.T(ctx, "sso.settings.login_url") }</dt>
|
||||
<dd class="break-all font-mono text-xs leading-5">{ s.LoginURL }</dd>
|
||||
</dl>
|
||||
if len(s.Providers) > 0 {
|
||||
<table class="mb-12 w-full max-w-4xl text-left text-sm">
|
||||
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
|
||||
<tr>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "sso.field.name") }</th>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "sso.field.issuer") }</th>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "sso.field.auto_provision") }</th>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "sso.field.enabled") }</th>
|
||||
<th class="py-2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-rule">
|
||||
for _, pr := range s.Providers {
|
||||
<tr class="align-top">
|
||||
<td class="py-2.5 pr-4">{ pr.Name }</td>
|
||||
<td class="py-2.5 pr-4 break-all font-mono text-xs">{ pr.Issuer }</td>
|
||||
<td class="py-2.5 pr-4">@yesNo(pr.AutoProvision)</td>
|
||||
<td class="py-2.5 pr-4">@yesNo(pr.Enabled)</td>
|
||||
<td class="py-2.5 text-right">
|
||||
<details class="inline-block text-left">
|
||||
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "sso.action.edit") }</summary>
|
||||
<div class="mt-4 w-80">
|
||||
@ssoForm(pr, "put", "/org/sso/"+pr.ID)
|
||||
<button
|
||||
type="button"
|
||||
data-delete={ "/org/sso/" + pr.ID }
|
||||
data-confirm={ i18n.T(ctx, "sso.action.delete_confirm") }
|
||||
class="mt-4 text-sm text-down hover:underline"
|
||||
>{ i18n.T(ctx, "sso.action.delete") }</button>
|
||||
</div>
|
||||
</details>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
<section class="max-w-md">
|
||||
<h2 class="mb-4 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "sso.settings.add") }</h2>
|
||||
@ssoForm(SSOProvider{Enabled: true}, "post", "/org/sso")
|
||||
</section>
|
||||
}
|
||||
}
|
||||
|
||||
templ yesNo(v bool) {
|
||||
if v {
|
||||
<span class="text-up">●</span> { i18n.T(ctx, "common.yes") }
|
||||
} else {
|
||||
<span class="text-unknown">●</span> { i18n.T(ctx, "common.no") }
|
||||
}
|
||||
}
|
||||
|
||||
templ ssoForm(pr SSOProvider, method, action string) {
|
||||
<form data-api={ action } data-method={ method } data-next="/settings/sso">
|
||||
@formError()
|
||||
@valueField(i18n.T(ctx, "sso.field.name"), "name", pr.Name, "", true)
|
||||
@valueField(i18n.T(ctx, "sso.field.issuer"), "issuer", pr.Issuer, "https://login.example.com/realms/acme", true)
|
||||
@valueField(i18n.T(ctx, "sso.field.client_id"), "client_id", pr.ClientID, "", true)
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "sso.field.client_secret") }</span>
|
||||
<input
|
||||
class="w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink"
|
||||
type="password"
|
||||
name="client_secret"
|
||||
autocomplete="off"
|
||||
if pr.HasSecret {
|
||||
placeholder={ i18n.T(ctx, "sso.field.client_secret_keep") }
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "sso.field.allowed_domains") }</span>
|
||||
<input
|
||||
class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
|
||||
name="allowed_domains"
|
||||
data-list
|
||||
value={ pr.AllowedDomains }
|
||||
placeholder="example.com, example.org"
|
||||
/>
|
||||
<span class="mt-1 block text-xs text-muted">{ i18n.T(ctx, "sso.field.allowed_domains_hint") }</span>
|
||||
</label>
|
||||
@checkbox(i18n.T(ctx, "sso.field.auto_provision"), "auto_provision", pr.AutoProvision)
|
||||
@checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", pr.Enabled)
|
||||
@submit(i18n.T(ctx, "common.save"))
|
||||
</form>
|
||||
}
|
||||
|
||||
templ valueField(label, name, value, placeholder string, required bool) {
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ label }</span>
|
||||
<input
|
||||
class="w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink"
|
||||
name={ name }
|
||||
value={ value }
|
||||
placeholder={ placeholder }
|
||||
required?={ required }
|
||||
/>
|
||||
</label>
|
||||
}
|
||||
|
||||
templ checkbox(label, name string, checked bool) {
|
||||
<label class="mb-3 flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" name={ name } checked?={ checked } class="accent-ink"/>
|
||||
{ label }
|
||||
</label>
|
||||
}
|
||||
Reference in new issue
Block a user