Skip to content

Commit 6f72928

Browse files
authored
feat(users,branding,ui): OAuth defaults, domain validation, Microsoft display name, native links & brandable login (#1343)
* fix(users): use signup_default_role for OAuth signups under allow_signup (#1332) * feat(users): validate trusted OAuth domains and add Microsoft display name (#1336, #1338) * fix(users): mark OAuth login links with data-native-link (#1339) * feat(branding,users,ui): brand the login page without overriding it (#1340) * fix: address code review findings (round 1, pass 1) * fix: address code review findings (round 1, pass 2) * fix: address code review findings (round 1, pass 3) * fix(branding): guard undefined fields when reconciling publish response
1 parent c987ca6 commit 6f72928

45 files changed

Lines changed: 1065 additions & 168 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ All notable changes to this project are documented in this file. The format is b
1919
- Core: `warn_ignored_env_vars` (invoked automatically at boot by `ModuleSettingsRegistry.register` for `DbBackedSettings` subclasses) logs one warning per leftover `SM_<MODULE>_*` environment variable without logging its value, naming the DB setting to configure instead (#1329).
2020
- Hosting: `HostSettings.csp_frame_src` (`SM_CSP_FRAME_SRC`, live runtime setting accepting a JSON array or comma-separated origins) allows permitting external iframe embed origins in CSP `frame-src` (`'self' blob: <origins>`) without weakening `script-src` or `default-src` (#1331).
2121
- Inertia / Hosting: `HostSettings.inertia_encrypt_history` (`SM_INERTIA_ENCRYPT_HISTORY`, default `true`, live runtime setting), `InertiaConfig.encrypt_history`, `inertia.encrypt_history(enabled=...)`, and per-response `inertia.render(..., encrypt_history=True|False|None)` allow opting out of (or back into) Inertia history encryption host-wide or per page, with `history.state` guidance added to `docs/frontend/inertia.md` (#1334).
22+
- Users: add `oauth_microsoft_display_name` (default `"Microsoft"`) on `UsersSettings` so apps can customize the Microsoft sign-in button label, matching `oauth_oidc_display_name` (#1338).
23+
- Branding / Users / UI: let apps brand the stock login page without overriding it — add optional `login_heading` and `login_tagline` fields to `BrandingSettings` (shared as `branding.loginHeading` / `branding.loginTagline` and editable at `/admin/branding` and per tenant), add a `LoginAside` layout override on `LayoutComponents` (`registry.registerLayout('LoginAside', ...)`), and export `LoginForm`, `WaitingOnYou`, `DemoSignIn`, `useLoginState`, and `signIn` from `@simple-module-py/users/ui` (`modules/users/users/ui/index.ts`) (#1340).
24+
25+
### Changed
26+
27+
- Users: **Behaviour change:** OAuth signups under `allow_signup` (for providers not in `oauth_signup_providers`) now receive `signup_default_role` instead of the hard-coded `user` role, matching local self-signup (#1332).
28+
29+
### Fixed
30+
31+
- Users: validate `oauth_trusted_email_domains` entries in `normalize_domain` as bare DNS hostnames after IDNA encoding, rejecting URLs, paths, ports, queries, fragments, whitespace, empty labels, leading/trailing hyphens, and oversized labels/domains (#1336).
32+
- Users: mark OAuth provider links in `LoginForm` with `data-native-link` so `startSpaLinkInterception` does not intercept provider redirects as Inertia XHRs and trigger CSP `connect-src 'self'` errors (#1339).
2233

2334
## [0.0.51] — 2026-11-29
2435

‎docs/frontend/extensions.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,22 @@ still enforce authorization, and tenant routes must use the active tenant.
8080
## Layout chrome and icons
8181

8282
The app-level `LayoutComponentsProvider` supplies `UserMenu`, `Topbar`,
83-
`AppLayout`, and `ErrorLayout`. `UserMenu` and `Topbar` default to
83+
`AppLayout`, `ErrorLayout`, and `LoginAside`. `UserMenu` and `Topbar` default to
8484
`SidebarUserMenu` and `AppTopbar`; `AppLayout` replaces the signed-in non-admin
8585
shell used by `users/pages/Profile.tsx` (via `AppShellLayout`) and non-admin
8686
`ErrorPage` views; `ErrorLayout` overrides `ErrorShell` everywhere (taking
87-
precedence over both `AppLayout` and `AdminLayout`). Exported
88-
`LayoutComponents` describes these contracts.
87+
precedence over both `AppLayout` and `AdminLayout`); `LoginAside` replaces the
88+
default `AuthSplitAside` column on `users/pages/Login.tsx` while keeping the
89+
stock login form and OAuth flows intact. Exported `LayoutComponents` describes
90+
these contracts.
8991

9092
```tsx
9193
export function register(registry: ExtensionRegistry) {
9294
registry.registerLayout('UserMenu', MyUserMenu);
9395
registry.registerLayout('Topbar', MyTopbar);
9496
registry.registerLayout('AppLayout', MyAppShell);
9597
registry.registerLayout('ErrorLayout', MyErrorShell);
98+
registry.registerLayout('LoginAside', MyLoginAside);
9699
registry.registerIcon('my_module.orbit', OrbitIcon);
97100
}
98101
```

‎docs/modules/branding.md‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Every JSON endpoint — including the reads — requires `branding.manage`; they
4242
| `DELETE /api/branding/logo-dark` | → `BrandingOut` (dark logo cleared) |
4343
| `DELETE /api/branding/favicon` | → `BrandingOut` (favicon cleared) |
4444

45-
`PUT /` only touches the text fields (`app_name`, `primary_color`, `design_pack`, `banner_message`, `banner_severity`); images are set and cleared through their dedicated upload/delete routes. A `design_pack` slug that no installed module registered is rejected with `422` — accepting it would put `"<slug>-root"` on the document with no stylesheet behind it, so the site would look unchanged with nothing in the UI explaining why.
45+
`PUT /` only touches the text fields (`app_name`, `primary_color`, `design_pack`, `banner_message`, `banner_severity`, `footer_text`, `footer_links`, `login_heading`, `login_tagline`); images are set and cleared through their dedicated upload/delete routes. A `design_pack` slug that no installed module registered is rejected with `422` — accepting it would put `"<slug>-root"` on the document with no stylesheet behind it, so the site would look unchanged with nothing in the UI explaining why.
4646

4747
### API (tenant)
4848

@@ -132,8 +132,8 @@ from branding.contracts import BrandingOut, BrandingUpdate
132132

133133
| Class | Purpose |
134134
|---|---|
135-
| `BrandingOut` | Current branding with images resolved to URLs: `app_name`, `primary_color`, `design_pack`, `logo_url`, `logo_dark_url`, `favicon_url`, `banner_message`, `banner_severity`. |
136-
| `BrandingUpdate` | Editable text fields, all optional: `app_name`, `primary_color`, `design_pack`, `banner_message`, `banner_severity`. |
135+
| `BrandingOut` | Current branding with images resolved to URLs: `app_name`, `primary_color`, `design_pack`, `logo_url`, `logo_dark_url`, `favicon_url`, `banner_message`, `banner_severity`, `footer_text`, `footer_links`, `login_heading`, `login_tagline`. |
136+
| `BrandingUpdate` | Editable text fields, all optional: `app_name`, `primary_color`, `design_pack`, `banner_message`, `banner_severity`, `footer_text`, `footer_links`, `login_heading`, `login_tagline`. |
137137

138138
`BrandingUpdate` is the strict one. An unknown `banner_severity` is a clear `422` here, while the settings validator normalises it to `info` — settings hydrate from the DB, where a hand-edited row must degrade to a readable banner rather than stop the app from booting. `design_pack` and `primary_color` are shape-checked in the DTO for the same reason: a malformed value becomes a `422` instead of a `500` when `BrandingSettings` re-validates.
139139

@@ -156,6 +156,8 @@ DB-backed via `register_module_settings`; pydantic defaults seed at boot. Edited
156156
| `banner_message` | `""` | Site-wide announcement text (≤ 500 chars); `""` ⇒ no banner. |
157157
| `banner_severity` | `"info"` | One of `info`, `warning`, `danger`. Unknown values normalise to `info`. |
158158
| `footer_links` | `[]` | Up to 6 `{label, href}` links shown in the site footer; `[]` ⇒ show the framework's own links. |
159+
| `login_heading` | `""` | Optional login split-aside heading (≤ 120 chars, no control characters); `""` ⇒ login page uses its default i18n copy. |
160+
| `login_tagline` | `""` | Optional login split-aside tagline (≤ 300 chars, no control characters); `""` ⇒ login page uses its default i18n copy. |
159161

160162
`app_name` rejects control characters, not just blanks: the name is used in HTML titles and — critically — email `Subject` headers, where an embedded CR/LF would survive a bare `strip()` and then raise, breaking every transactional email.
161163

@@ -235,20 +237,25 @@ On startup the module registers a shared-props provider (`register_inertia_share
235237
"logoDarkUrl": "/api/branding/logo-dark?v=<file id>",
236238
"faviconUrl": "/api/branding/favicon?v=<file id>",
237239
"banner": { "message": "Maintenance at 22:00 UTC", "severity": "warning" },
238-
"footerLinks": [{ "label": "Handbook", "href": "https://acme.example.org/handbook" }]
240+
"footerLinks": [{ "label": "Handbook", "href": "https://acme.example.org/handbook" }],
241+
"loginHeading": "Welcome to Acme",
242+
"loginTagline": "Sign in with your workspace account."
239243
}
240244
}
241245
```
242246

243-
`primaryColor` and `designPack` are `null` when unset; the three image URLs are `null` when no file is configured. `banner` is `null` when no message is set, so the frontend renders nothing at all rather than an empty bar. `footerLinks` is `null` when none are configured, which is what tells the frontend to keep the framework's own links rather than render an empty row.
247+
`primaryColor`, `designPack`, `loginHeading`, and `loginTagline` are `null` when unset; the three image URLs are `null` when no file is configured. `banner` is `null` when no message is set, so the frontend renders nothing at all rather than an empty bar. `footerLinks` is `null` when none are configured, which is what tells the frontend to keep the framework's own links rather than render an empty row.
244248

245249
The provider is defensive — it returns `{}` if branding state isn't mounted yet, so a half-booted app never errors a render. Because changes go through the settings store, a save hot-reloads `app.state.branding.settings`; the next render reflects the new values without a restart.
246250

247251
## Per-tenant branding
248252

249253
With `multi_tenant` on, a tenant can override part of the theme for itself
250-
(#373): `app_name`, `primary_color`, `design_pack`, `footer_text` and the three
251-
images. Each is a settings key (`branding.<field>`) declared
254+
(#373): `app_name`, `primary_color`, `design_pack`, `footer_text`,
255+
`login_heading`, `login_tagline` and the three images. Clearing system
256+
`login_heading`/`login_tagline` restores the login page's translated defaults,
257+
while a blank or whitespace-only tenant override inherits the platform copy.
258+
Each is a settings key (`branding.<field>`) declared
252259
`tenant_overridable`, stored at settings' TENANT scope, and edited by tenant
253260
owners/admins on the organisation settings page (`/tenants/settings`) — scalars
254261
through `/api/settings/tenant/current/{key}`, images through

‎docs/modules/users.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Edit the remaining settings under Users at `/admin/settings/`:
196196
| Field | Default |
197197
|---|---|
198198
| `allow_signup` | `False` |
199-
| `signup_default_role` | `"user"` — existing role for local self-signup; blank or a missing role grants none |
199+
| `signup_default_role` | `"user"` — existing role for local self-signup and OAuth signups under `allow_signup` (when the provider is not in `oauth_signup_providers`); blank or a missing role grants none |
200200
| `require_verification` | `True` |
201201
| `reset_password_token_lifetime_seconds` | `3600` |
202202
| `verification_token_lifetime_seconds` | `604_800` (7 days) |
@@ -221,7 +221,7 @@ Edit the remaining settings under Users at `/admin/settings/`:
221221
| `demo_read_only` | `True` |
222222
| `oauth_google_client_id` / `oauth_google_client_secret` | `""` — Google OAuth |
223223
| `oauth_github_client_id` / `oauth_github_client_secret` | `""` — GitHub OAuth |
224-
| `oauth_microsoft_client_id` / `oauth_microsoft_client_secret` / `oauth_microsoft_tenant` | `""` / `""` / `"common"` — Microsoft (Entra ID) |
224+
| `oauth_microsoft_client_id` / `oauth_microsoft_client_secret` / `oauth_microsoft_tenant` / `oauth_microsoft_display_name` | `""` / `""` / `"common"` / `"Microsoft"` — Microsoft (Entra ID); `oauth_microsoft_display_name` sets the sign-in button label |
225225
| `oauth_microsoft_trust_tenant_upn` | `False` — treat a member's UPN (the `upn` claim, else `preferred_username`) as a verified email; only with a tenant GUID (see [Signing in pre-approved staff with Microsoft](#signing-in-pre-approved-staff-with-microsoft)) |
226226
| `oauth_microsoft_discovery_url` | `""` — development/testing only: take Microsoft's endpoints from this discovery document, for a local IdP (see [Microsoft sign-in without Entra](#microsoft-sign-in-without-entra-development)) |
227227
| `oauth_signup_providers` / `oauth_signup_default_role` | `[]` / `""` — providers that create accounts on first sign-in with `allow_signup` off, and the role those accounts get (see [Provisioning accounts through SSO](#provisioning-accounts-through-sso)) |
@@ -809,7 +809,15 @@ With `allow_signup` off, an OAuth sign-in for an identity nobody holds is refuse
809809

810810
- `oauth_signup_providers` (for example `["microsoft"]`): a first sign-in through a listed provider creates the account, as an external (SSO-only) user, when the provider proved the email. An unproven email is refused even with `allow_signup` on, so listing a provider never widens what it can do. For Microsoft that means turning on the trusted-tenant policy above; GitHub needs a verified primary email; generic OIDC needs `email_verified: true`.
811811
- `oauth_signup_default_role`: the role those accounts get, with `allow_signup` on too: a listed provider's accounts use this setting independently of local self-signup's `signup_default_role`. Blank (the default) means none: the account signs in but holds no permissions until an admin grants a role. Every account the provider creates gets this role, so name one whose permissions you would give to anyone in that directory; `admin` is refused, and a name with no matching role is logged and grants nothing.
812-
- Local registration (`POST /api/users/auth/register`, `/users/register`, the "Sign up" links) still follows `allow_signup` alone. Its `signup_default_role` defaults to `user`; set it to an existing role such as `labeller` to grant that role on signup. The role is looked up, never created: a missing role logs a warning and grants nothing, as with `oauth_signup_default_role`. Blank also grants none, and `admin` is refused. Configure it in the admin settings editor; it applies to new accounts, leaving existing assignments unchanged. Providers that are not listed keep the old rule: they create accounts only with `allow_signup` on, and those accounts get the `user` role.
812+
- Local registration (`POST /api/users/auth/register`, `/users/register`, the "Sign up" links) still follows `allow_signup` alone. Its `signup_default_role` defaults to `user`; set it to an existing role such as `labeller` to grant that role on signup. The role is looked up, never created: a missing role logs a warning and grants nothing, as with `oauth_signup_default_role`. Blank also grants none, and `admin` is refused. Configure it in the admin settings editor; it applies to new accounts, leaving existing assignments unchanged. Providers that are not in `oauth_signup_providers` create accounts only with `allow_signup` on, and those accounts also receive `signup_default_role` (none when blank).
813+
814+
### Customising the login page
815+
816+
You can brand `/users/login` without replacing the page:
817+
818+
1. **Heading and tagline via Branding:** set `login_heading` and `login_tagline` in `/admin/branding` (or `BrandingSettings`). When set, the default `AuthSplitAside` column renders them in place of the built-in `users.login.aside_heading` / `users.login.aside_body` copy.
819+
2. **Custom split aside via the extension registry:** register a `LoginAside` component with `registry.registerLayout('LoginAside', MyLoginAside)` in your host's extension setup (see [Frontend extension points](../frontend/extensions.md)). This replaces the left-hand column with your own illustration or layout while keeping `LoginForm`, OAuth buttons, CSRF, `oauth_error`, verification resend, and demo sign-in intact.
820+
3. **Composing a custom login page:** when you do need to override `Users/Login`, import `LoginForm`, `WaitingOnYou`, `DemoSignIn`, `useLoginState`, and `signIn` from `@simple-module-py/users/ui` (`modules/users/users/ui/index.ts`) instead of re-implementing login state and OAuth links.
813821

814822
### Trusted email domains
815823

‎host/client_app/i18n/generated-resources.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ const resources = {
467467
'branding.manage.footer_links_label': '',
468468
'branding.manage.footer_text_placeholder': '',
469469
'branding.manage.images_label': '',
470+
'branding.manage.login_copy_label': '',
471+
'branding.manage.login_heading_label': '',
472+
'branding.manage.login_heading_placeholder': '',
473+
'branding.manage.login_tagline_label': '',
474+
'branding.manage.login_tagline_placeholder': '',
470475
'branding.manage.logo_dark_label': '',
471476
'branding.manage.logo_label': '',
472477
'branding.manage.preset_label': '',
@@ -499,13 +504,17 @@ const resources = {
499504
'branding.tenant_setting_labels.design_pack': '',
500505
'branding.tenant_setting_labels.favicon_file_id': '',
501506
'branding.tenant_setting_labels.footer_text': '',
507+
'branding.tenant_setting_labels.login_heading': '',
508+
'branding.tenant_setting_labels.login_tagline': '',
502509
'branding.tenant_setting_labels.logo_dark_file_id': '',
503510
'branding.tenant_setting_labels.logo_file_id': '',
504511
'branding.tenant_setting_labels.primary_color': '',
505512
'branding.tenant_settings.app_name': '',
506513
'branding.tenant_settings.design_pack': '',
507514
'branding.tenant_settings.favicon_file_id': '',
508515
'branding.tenant_settings.footer_text': '',
516+
'branding.tenant_settings.login_heading': '',
517+
'branding.tenant_settings.login_tagline': '',
509518
'branding.tenant_settings.logo_dark_file_id': '',
510519
'branding.tenant_settings.logo_file_id': '',
511520
'branding.tenant_settings.primary_color': '',
@@ -1916,6 +1925,8 @@ const resources = {
19161925
'users.settings_form.fields.oauth_microsoft_client_secret.label': '',
19171926
'users.settings_form.fields.oauth_microsoft_discovery_url.help': '',
19181927
'users.settings_form.fields.oauth_microsoft_discovery_url.label': '',
1928+
'users.settings_form.fields.oauth_microsoft_display_name.help': '',
1929+
'users.settings_form.fields.oauth_microsoft_display_name.label': '',
19191930
'users.settings_form.fields.oauth_microsoft_tenant.help': '',
19201931
'users.settings_form.fields.oauth_microsoft_tenant.label': '',
19211932
'users.settings_form.fields.oauth_microsoft_trust_tenant_upn.help': '',

‎host/client_app/i18n/keys.generated.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ export const keys = {
649649
footer_links_label: 'branding.manage.footer_links_label',
650650
footer_text_placeholder: 'branding.manage.footer_text_placeholder',
651651
images_label: 'branding.manage.images_label',
652+
login_copy_label: 'branding.manage.login_copy_label',
653+
login_heading_label: 'branding.manage.login_heading_label',
654+
login_heading_placeholder: 'branding.manage.login_heading_placeholder',
655+
login_tagline_label: 'branding.manage.login_tagline_label',
656+
login_tagline_placeholder: 'branding.manage.login_tagline_placeholder',
652657
logo_dark_label: 'branding.manage.logo_dark_label',
653658
logo_label: 'branding.manage.logo_label',
654659
preset_label: 'branding.manage.preset_label',
@@ -688,6 +693,8 @@ export const keys = {
688693
design_pack: 'branding.tenant_setting_labels.design_pack',
689694
favicon_file_id: 'branding.tenant_setting_labels.favicon_file_id',
690695
footer_text: 'branding.tenant_setting_labels.footer_text',
696+
login_heading: 'branding.tenant_setting_labels.login_heading',
697+
login_tagline: 'branding.tenant_setting_labels.login_tagline',
691698
logo_dark_file_id: 'branding.tenant_setting_labels.logo_dark_file_id',
692699
logo_file_id: 'branding.tenant_setting_labels.logo_file_id',
693700
primary_color: 'branding.tenant_setting_labels.primary_color',
@@ -697,6 +704,8 @@ export const keys = {
697704
design_pack: 'branding.tenant_settings.design_pack',
698705
favicon_file_id: 'branding.tenant_settings.favicon_file_id',
699706
footer_text: 'branding.tenant_settings.footer_text',
707+
login_heading: 'branding.tenant_settings.login_heading',
708+
login_tagline: 'branding.tenant_settings.login_tagline',
700709
logo_dark_file_id: 'branding.tenant_settings.logo_dark_file_id',
701710
logo_file_id: 'branding.tenant_settings.logo_file_id',
702711
primary_color: 'branding.tenant_settings.primary_color',
@@ -2689,6 +2698,10 @@ export const keys = {
26892698
help: 'users.settings_form.fields.oauth_microsoft_discovery_url.help',
26902699
label: 'users.settings_form.fields.oauth_microsoft_discovery_url.label',
26912700
},
2701+
oauth_microsoft_display_name: {
2702+
help: 'users.settings_form.fields.oauth_microsoft_display_name.help',
2703+
label: 'users.settings_form.fields.oauth_microsoft_display_name.label',
2704+
},
26922705
oauth_microsoft_tenant: {
26932706
help: 'users.settings_form.fields.oauth_microsoft_tenant.help',
26942707
label: 'users.settings_form.fields.oauth_microsoft_tenant.label',

0 commit comments

Comments
 (0)