openvibers/openvibe.network Commits

Network: a site client created first as a service principal gets the site's name, so sign-in says "OpenVibe.Food", not "OpenVibe.food (service)" (#88)

OP OpenVibers committed 8 Oct 2026 · dedc9d4090 · 2 files, +32 −1

The seed renames a contract client whose name is still the principal placeholder (OpenVibe.<id> (service)); a name someone chose stays. Fixes actor, food, help and work on the sign-in page. test/client-names.test.js.

Changes

ddiff --git a/server/db/database.js b/server/db/database.js
iindex 127f6ce7..7d7513c5 100644
---- a/server/db/database.js
++++ b/server/db/database.js
@@@ -117,7 +117,7 @@ async function seedDb(db, { log = console } = {}) {
];
let seededAny = false;
for (const c of contractClients) {
-- const existing = await db.prepare('SELECT client_id, redirect_uris FROM oauth_clients WHERE client_id = ?').get(c.client_id);
++ const existing = await db.prepare('SELECT client_id, name, redirect_uris FROM oauth_clients WHERE client_id = ?').get(c.client_id);
if (!existing) {
await db.prepare('INSERT INTO oauth_clients (client_id, client_secret, name, redirect_uris, is_first_party) VALUES (?, ?, ?, ?, 1)')
.run(c.client_id, uuidv4(), c.name, JSON.stringify(c.redirect_uris));
@@@ -126,6 +126,13 @@ async function seedDb(db, { log = console } = {}) {
continue;
}
await mergeRedirectUris(db, c.client_id, c.redirect_uris, { log });
++ // A client created first as a service principal carries the placeholder name "OpenVibe.<id> (service)",
++ // which the sign-in page shows people ("Sign in to OpenVibe.food (service)"). Give it the site's name; a
++ // name someone chose stays.
++ if (existing.name === `OpenVibe.${c.client_id} (service)`) {
++ await db.prepare('UPDATE oauth_clients SET name = ? WHERE client_id = ?').run(c.name, c.client_id);
++ log.log(`[DB] OAuth2 client ${c.client_id} renamed to ${c.name}`);
++ }
}
if (seededAny) console.log('[DB] New OAuth2 clients seeded; their secrets are in oauth_clients (they are never logged).');
}
ddiff --git a/test/client-names.test.js b/test/client-names.test.js
nnew file mode 100644
iindex 00000000..bbbd5f3f
---- /dev/null
++++ b/test/client-names.test.js
@@@ -0,0 +1,24 @@
++'use strict';
++// A site's OAuth client created first as a service principal (server/setup/service-principal.js names it
++// "OpenVibe.<id> (service)") gets the site's name from the seed, so the sign-in page says "OpenVibe.Food"; a name someone
++// chose is left alone.
++const assert = require('assert');
++const { getDb, seedDb } = require('../server/db/database');
++
++(async () => {
++ const db = getDb();
++ const log = { log() {}, warn() {}, error() {} };
++ const quiet = console.log; console.log = () => {};
++ await seedDb(db, { log });
++
++ await db.prepare("UPDATE oauth_clients SET name = 'OpenVibe.food (service)' WHERE client_id = 'food'").run();
++ await db.prepare("UPDATE oauth_clients SET name = 'Our own name' WHERE client_id = 'help'").run();
++ await seedDb(db, { log });
++ console.log = quiet;
++
++ const name = async (id) => (await db.prepare('SELECT name FROM oauth_clients WHERE client_id = ?').get(id)).name;
++ assert.strictEqual(await name('food'), 'OpenVibe.Food', 'the placeholder name becomes the site name');
++ assert.strictEqual(await name('help'), 'Our own name', 'a chosen name stays');
++ assert.strictEqual(await name('work'), 'OpenVibe.Work', 'a seeded client has its name');
++ console.log('client-names: ok');
++})().catch((err) => { console.error(err); process.exit(1); });