commit
Updates
diff --git a/.svelte-check/svelte/web/src/components/++ClientFields.svelte.ts b/.svelte-check/svelte/web/src/components/++ClientFields.svelte.ts
index 14c6124..f531abd 100644
--- a/.svelte-check/svelte/web/src/components/++ClientFields.svelte.ts
+++ b/.svelte-check/svelte/web/src/components/++ClientFields.svelte.ts
@@ -3,6 +3,7 @@
export interface ClientValues {
name: string;
homeUrl: string;
+ iconUrl: string;
redirectUris: string;
postLogoutRedirectUris: string;
allowedGroups: string[];
@@ -25,6 +26,7 @@ async () => {
{ const $$_dleiF0C = __sveltets_2_ensureComponent(Field); const $$_dleiF0 = new $$_dleiF0C({ target: __sveltets_2_any(), props: { "label":`Name`,"name":`name`,value:values.name,"required":true,"maxlength":100,"autocomplete":`off`,"hint":`Shown to people when they're asked to sign in.`,}});/*Ωignore_startΩ*/() => values.name = __sveltets_2_any(null);/*Ωignore_endΩ*/$$_dleiF0.$$bindings = 'value';}
{ const $$_dleiF0C = __sveltets_2_ensureComponent(Field); const $$_dleiF0 = new $$_dleiF0C({ target: __sveltets_2_any(), props: { "label":`Website`,"name":`homeUrl`,"type":`url`,value:values.homeUrl,"maxlength":2048,"autocomplete":`off`,"placeholder":`https://app.example.com/`,"hint":`Optional. Where the app lives: with one, it's listed on everyone's “Your apps” page (if their groups allow it).`,}});/*Ωignore_startΩ*/() => values.homeUrl = __sveltets_2_any(null);/*Ωignore_endΩ*/$$_dleiF0.$$bindings = 'value';}
+ { const $$_dleiF0C = __sveltets_2_ensureComponent(Field); const $$_dleiF0 = new $$_dleiF0C({ target: __sveltets_2_any(), props: { "label":`Icon`,"name":`iconUrl`,"type":`url`,value:values.iconUrl,"maxlength":2048,"autocomplete":`off`,"placeholder":`https://app.example.com/favicon.png`,"hint":`Optional. An https image shown for the app on “Your apps”; without one, its first letter is used.`,}});/*Ωignore_startΩ*/() => values.iconUrl = __sveltets_2_any(null);/*Ωignore_endΩ*/$$_dleiF0.$$bindings = 'value';}
{ svelteHTML.createElement("label", { "class":`field`,});
{ svelteHTML.createElement("span", {}); }
{ svelteHTML.createElement("textarea", { "bind:value":values.redirectUris,"rows":3,"required":true,"placeholder":`https://app.example.com/auth/callback`,});/*Ωignore_startΩ*/() => values.redirectUris = __sveltets_2_any(null);/*Ωignore_endΩ*/ }
diff --git a/.svelte-check/svelte/web/src/pages/++Apps.svelte.ts b/.svelte-check/svelte/web/src/pages/++Apps.svelte.ts
index e17e857..c739012 100644
--- a/.svelte-check/svelte/web/src/pages/++Apps.svelte.ts
+++ b/.svelte-check/svelte/web/src/pages/++Apps.svelte.ts
@@ -21,12 +21,16 @@ function $$render() {
id: string;
name: string;
url: string;
+ iconUrl: string | null;
}
let apps = $state<App[] | null>(null);
const load = new Action();
load.run(async () => (apps = await api<App[]>("/api/apps")));
+ // Icons that didn't load fall back to the app's initial
+ let brokenIcons = $state(new Set<string>());
+
function host(url: string): string {
try {
return new URL(url).host;
@@ -57,7 +61,11 @@ if(apps){
for(let app of __sveltets_2_ensureArray(apps)){app.id;
{ svelteHTML.createElement("li", {});
{ svelteHTML.createElement("a", { "class":`app-tile`,"href":app.url,"rel":`noopener`,});
- { svelteHTML.createElement("span", { "class":`app-mark`,"aria-hidden":`true`,});app.name.slice(0, 1).toUpperCase(); }
+ if(app.iconUrl && !brokenIcons.has(app.id)){
+ { svelteHTML.createElement("img", { "class":`app-mark`,"src":app.iconUrl,"alt":"","referrerpolicy":`no-referrer`,"onerror":() => (brokenIcons = new Set(brokenIcons).add(app.id)),});}
+ }else{
+ { svelteHTML.createElement("span", { "class":`app-mark`,"aria-hidden":`true`,});app.name.slice(0, 1).toUpperCase(); }
+ }
{ svelteHTML.createElement("span", { "class":`app-text`,});
{ svelteHTML.createElement("strong", {});app.name; }
{ svelteHTML.createElement("small", { "class":`muted`,});host(app.url); }
diff --git a/.svelte-check/svelte/web/src/pages/admin/++ClientDetail.svelte.ts b/.svelte-check/svelte/web/src/pages/admin/++ClientDetail.svelte.ts
index f9a7152..1a7da0e 100644
--- a/.svelte-check/svelte/web/src/pages/admin/++ClientDetail.svelte.ts
+++ b/.svelte-check/svelte/web/src/pages/admin/++ClientDetail.svelte.ts
@@ -35,7 +35,7 @@ import { newSecrets, type ClientData } from "./Clients.svelte";
let client = $state<ClientData | null>(null);
let groups = $state<GroupOption[]>([]);
- let values = $state<ClientValues>({ name: "", homeUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
+ let values = $state<ClientValues>({ name: "", homeUrl: "", iconUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
// A secret just created on the previous page (taken, so it's only ever shown
// once), or one from rotating it here.
let secret = $state<string | null>(
@@ -58,6 +58,7 @@ import { newSecrets, type ClientData } from "./Clients.svelte";
values = {
name: c.name,
homeUrl: c.homeUrl ?? "",
+ iconUrl: c.iconUrl ?? "",
redirectUris: c.redirectUris.join("\n"),
postLogoutRedirectUris: c.postLogoutRedirectUris.join("\n"),
allowedGroups: [...c.allowedGroups],
diff --git a/.svelte-check/svelte/web/src/pages/admin/++Clients.svelte.ts b/.svelte-check/svelte/web/src/pages/admin/++Clients.svelte.ts
index c9cf47d..3de00b7 100644
--- a/.svelte-check/svelte/web/src/pages/admin/++Clients.svelte.ts
+++ b/.svelte-check/svelte/web/src/pages/admin/++Clients.svelte.ts
@@ -4,6 +4,7 @@
id: string;
name: string;
homeUrl: string | null;
+ iconUrl: string | null;
isPublic: boolean;
redirectUris: string[];
postLogoutRedirectUris: string[];
@@ -45,7 +46,7 @@ function $$render() {
let clients = $state<ClientData[]>([]);
let groups = $state<GroupOption[]>([]);
- let values = $state<ClientValues>({ name: "", homeUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
+ let values = $state<ClientValues>({ name: "", homeUrl: "", iconUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
let type = $state<"confidential" | "public">("confidential");
let clientId = $state("");
const load = new Action();
diff --git a/migrations/0007_client_icon_urls.sql b/migrations/0007_client_icon_urls.sql
new file mode 100644
index 0000000..1d651fa
--- /dev/null
+++ b/migrations/0007_client_icon_urls.sql
@@ -0,0 +1,7 @@
+-- migrations/0007_client_icon_urls.sql
+-- Copyright (c) 2026 Clove Nytrix Doughmination Twilight
+-- Licensed under the DASL-1.2 Licence.
+
+-- An image shown for the app on the "Your apps" page. Apps without one get
+-- the first letter of their name instead.
+ALTER TABLE clients ADD COLUMN icon_url TEXT;
diff --git a/src/api/admin.ts b/src/api/admin.ts
index 584a01d..d91c1a7 100644
--- a/src/api/admin.ts
+++ b/src/api/admin.ts
@@ -14,6 +14,7 @@ import {
clientIdProblem,
homeUrlProblem,
emailProblem,
+ iconUrlProblem,
groupProblem,
normaliseUsername,
pictureProblem,
@@ -370,12 +371,15 @@ async function readClient(c: AppContext, b: Record<string, unknown>): Promise<Cl
const known = new Set((await listGroups(c.env)).map((g) => g.name));
const name = cleanText(str(b.name), 100);
const homeUrl = cleanText(str(b.homeUrl), 2048);
+ const iconUrl = cleanText(str(b.iconUrl), 2048);
const redirectUris = lines(str(b.redirectUris));
const postLogoutRedirectUris = lines(str(b.postLogoutRedirectUris));
if (!name) return "Applications need a name.";
const urlProblem = homeUrlProblem(homeUrl);
if (urlProblem) return urlProblem;
+ const iconProblem = iconUrlProblem(iconUrl);
+ if (iconProblem) return iconProblem;
if (redirectUris.length === 0) return "Add at least one redirect URI.";
if (redirectUris.length + postLogoutRedirectUris.length > 40) return "That's too many URIs.";
for (const uri of [...redirectUris, ...postLogoutRedirectUris]) {
@@ -385,6 +389,7 @@ async function readClient(c: AppContext, b: Record<string, unknown>): Promise<Cl
return {
name,
homeUrl,
+ iconUrl,
redirectUris: [...new Set(redirectUris)],
postLogoutRedirectUris: [...new Set(postLogoutRedirectUris)],
allowedGroups: strings(b.allowedGroups).filter((g) => known.has(g)),
@@ -397,6 +402,7 @@ function clientJson(c: AppContext, client: Client) {
id: client.id,
name: client.name,
homeUrl: client.homeUrl,
+ iconUrl: client.iconUrl,
isPublic: client.isPublic,
redirectUris: client.redirectUris,
postLogoutRedirectUris: client.postLogoutRedirectUris,
diff --git a/src/api/apps.ts b/src/api/apps.ts
index 6081180..ef20def 100644
--- a/src/api/apps.ts
+++ b/src/api/apps.ts
@@ -21,6 +21,6 @@ apps.get("/api/apps", requireUser, async (c) => {
return c.json(
clients
.filter((cl) => cl.homeUrl && clientAllows(cl, groups))
- .map((cl) => ({ id: cl.id, name: cl.name, url: cl.homeUrl })),
+ .map((cl) => ({ id: cl.id, name: cl.name, url: cl.homeUrl, iconUrl: cl.iconUrl })),
);
});
diff --git a/src/data/clients.ts b/src/data/clients.ts
index 70445d0..f07a66b 100644
--- a/src/data/clients.ts
+++ b/src/data/clients.ts
@@ -11,6 +11,7 @@ interface ClientRow {
id: string;
name: string;
home_url: string | null;
+ icon_url: string | null;
secret_hash: string | null;
redirect_uris: string;
post_logout_redirect_uris: string;
@@ -24,6 +25,8 @@ export interface Client {
name: string;
/** The app's own website, linked from "Your apps". */
homeUrl: string | null;
+ /** An image for the app on "Your apps"; its initial is used without one. */
+ iconUrl: string | null;
secretHash: string | null;
isPublic: boolean;
redirectUris: string[];
@@ -38,6 +41,7 @@ function toClient(row: ClientRow): Client {
id: row.id,
name: row.name,
homeUrl: row.home_url,
+ iconUrl: row.icon_url,
secretHash: row.secret_hash,
isPublic: row.secret_hash === null,
redirectUris: JSON.parse(row.redirect_uris) as string[],
@@ -61,6 +65,7 @@ export async function listClients(env: Env): Promise<Client[]> {
export interface ClientInput {
name: string;
homeUrl: string | null;
+ iconUrl: string | null;
redirectUris: string[];
postLogoutRedirectUris: string[];
allowedGroups: string[];
@@ -81,13 +86,14 @@ export async function createClient(
const ts = now();
try {
await env.DB.prepare(
- `INSERT INTO clients (id, name, home_url, secret_hash, redirect_uris, post_logout_redirect_uris, allowed_groups, created_at, updated_at)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
+ `INSERT INTO clients (id, name, home_url, icon_url, secret_hash, redirect_uris, post_logout_redirect_uris, allowed_groups, created_at, updated_at)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
)
.bind(
id,
input.name,
input.homeUrl,
+ input.iconUrl,
secret ? await sha256Hex(secret) : null,
JSON.stringify(input.redirectUris),
JSON.stringify(input.postLogoutRedirectUris),
@@ -105,12 +111,13 @@ export async function createClient(
export async function updateClient(env: Env, id: string, input: ClientInput): Promise<void> {
await env.DB.prepare(
- `UPDATE clients SET name = ?, home_url = ?, redirect_uris = ?, post_logout_redirect_uris = ?, allowed_groups = ?, updated_at = ?
+ `UPDATE clients SET name = ?, home_url = ?, icon_url = ?, redirect_uris = ?, post_logout_redirect_uris = ?, allowed_groups = ?, updated_at = ?
WHERE id = ?`,
)
.bind(
input.name,
input.homeUrl,
+ input.iconUrl,
JSON.stringify(input.redirectUris),
JSON.stringify(input.postLogoutRedirectUris),
JSON.stringify(input.allowedGroups),
diff --git a/src/lib/validate.ts b/src/lib/validate.ts
index 15e9503..c1aec4b 100644
--- a/src/lib/validate.ts
+++ b/src/lib/validate.ts
@@ -86,6 +86,17 @@ export function homeUrlProblem(url: string | null): string | null {
return "The website must use https (http is only allowed for localhost).";
}
+/** An app's icon: an absolute https URL, which the CSP's img-src allows. */
+export function iconUrlProblem(url: string | null): string | null {
+ if (url === null) return null;
+ try {
+ if (new URL(url).protocol !== "https:") return "Icon URLs must use https.";
+ } catch {
+ return "That icon URL isn't a valid URL.";
+ }
+ return url.length <= 2048 ? null : "That icon URL is too long.";
+}
+
/**
* Redirect URIs are matched exactly, so validation only has to make sure they
* are absolute, have no fragment, and use https (plain http only for loopback).
diff --git a/web/src/app.css b/web/src/app.css
index 1576bcd..3b436c3 100644
--- a/web/src/app.css
+++ b/web/src/app.css
@@ -786,6 +786,11 @@ table.compact td {
font-weight: 700;
}
+img.app-mark {
+ object-fit: contain;
+ padding: 0.35rem;
+}
+
.app-text {
display: flex;
flex-direction: column;
diff --git a/web/src/components/ClientFields.svelte b/web/src/components/ClientFields.svelte
index 9e05325..b16bca5 100644
--- a/web/src/components/ClientFields.svelte
+++ b/web/src/components/ClientFields.svelte
@@ -2,6 +2,7 @@
export interface ClientValues {
name: string;
homeUrl: string;
+ iconUrl: string;
redirectUris: string;
postLogoutRedirectUris: string;
allowedGroups: string[];
@@ -26,6 +27,16 @@
placeholder="https://app.example.com/"
hint="Optional. Where the app lives: with one, it's listed on everyone's “Your apps” page (if their groups allow it)."
/>
+<Field
+ label="Icon"
+ name="iconUrl"
+ type="url"
+ bind:value={values.iconUrl}
+ maxlength={2048}
+ autocomplete="off"
+ placeholder="https://app.example.com/favicon.png"
+ hint="Optional. An https image shown for the app on “Your apps”; without one, its first letter is used."
+/>
<label class="field">
<span>Redirect URIs</span>
<textarea bind:value={values.redirectUris} rows={3} required placeholder="https://app.example.com/auth/callback"></textarea>
diff --git a/web/src/pages/Apps.svelte b/web/src/pages/Apps.svelte
index 5fcd09c..e35e4df 100644
--- a/web/src/pages/Apps.svelte
+++ b/web/src/pages/Apps.svelte
@@ -11,12 +11,16 @@
id: string;
name: string;
url: string;
+ iconUrl: string | null;
}
let apps = $state<App[] | null>(null);
const load = new Action();
load.run(async () => (apps = await api<App[]>("/api/apps")));
+ // Icons that didn't load fall back to the app's initial
+ let brokenIcons = $state(new Set<string>());
+
function host(url: string): string {
try {
return new URL(url).host;
@@ -48,7 +52,17 @@
{#each apps as app (app.id)}
<li>
<a class="app-tile" href={app.url} rel="noopener">
- <span class="app-mark" aria-hidden="true">{app.name.slice(0, 1).toUpperCase()}</span>
+ {#if app.iconUrl && !brokenIcons.has(app.id)}
+ <img
+ class="app-mark"
+ src={app.iconUrl}
+ alt=""
+ referrerpolicy="no-referrer"
+ onerror={() => (brokenIcons = new Set(brokenIcons).add(app.id))}
+ />
+ {:else}
+ <span class="app-mark" aria-hidden="true">{app.name.slice(0, 1).toUpperCase()}</span>
+ {/if}
<span class="app-text">
<strong>{app.name}</strong>
<small class="muted">{host(app.url)}</small>
diff --git a/web/src/pages/admin/ClientDetail.svelte b/web/src/pages/admin/ClientDetail.svelte
index 2c36538..dfafc4a 100644
--- a/web/src/pages/admin/ClientDetail.svelte
+++ b/web/src/pages/admin/ClientDetail.svelte
@@ -18,7 +18,7 @@
let client = $state<ClientData | null>(null);
let groups = $state<GroupOption[]>([]);
- let values = $state<ClientValues>({ name: "", homeUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
+ let values = $state<ClientValues>({ name: "", homeUrl: "", iconUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
// A secret just created on the previous page (taken, so it's only ever shown
// once), or one from rotating it here.
let secret = $state<string | null>(
@@ -41,6 +41,7 @@
values = {
name: c.name,
homeUrl: c.homeUrl ?? "",
+ iconUrl: c.iconUrl ?? "",
redirectUris: c.redirectUris.join("\n"),
postLogoutRedirectUris: c.postLogoutRedirectUris.join("\n"),
allowedGroups: [...c.allowedGroups],
diff --git a/web/src/pages/admin/Clients.svelte b/web/src/pages/admin/Clients.svelte
index 0b81b29..9b49b56 100644
--- a/web/src/pages/admin/Clients.svelte
+++ b/web/src/pages/admin/Clients.svelte
@@ -3,6 +3,7 @@
id: string;
name: string;
homeUrl: string | null;
+ iconUrl: string | null;
isPublic: boolean;
redirectUris: string[];
postLogoutRedirectUris: string[];
@@ -31,7 +32,7 @@
let clients = $state<ClientData[]>([]);
let groups = $state<GroupOption[]>([]);
- let values = $state<ClientValues>({ name: "", homeUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
+ let values = $state<ClientValues>({ name: "", homeUrl: "", iconUrl: "", redirectUris: "", postLogoutRedirectUris: "", allowedGroups: [] });
let type = $state<"confidential" | "public">("confidential");
let clientId = $state("");
const load = new Action();