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)
Changes
@@@ -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).');}nnew file mode 100644@@@ -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); });
@@ -117,7 +117,7 @@ async function seedDb(db, { log = console } = {}) {
@@ -117,7 +117,7 @@ async function seedDb(db, { log = console } = {}) {
];
];
let seededAny = false;
let seededAny = false;
for (const c of contractClients) {
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) {
if (!existing) {
await db.prepare('INSERT INTO oauth_clients (client_id, client_secret, name, redirect_uris, is_first_party) VALUES (?, ?, ?, ?, 1)')
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));
.run(c.client_id, uuidv4(), c.name, JSON.stringify(c.redirect_uris));
@@ -126,6 +126,13 @@ async function seedDb(db, { log = console } = {}) {
@@ -126,6 +126,13 @@ async function seedDb(db, { log = console } = {}) {
continue;
continue;
}
}
await mergeRedirectUris(db, c.client_id, c.redirect_uris, { log });
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).');
if (seededAny) console.log('[DB] New OAuth2 clients seeded; their secrets are in oauth_clients (they are never logged).');
}
}
new file mode 100644
new file mode 100644
@@ -0,0 +1,24 @@
@@ -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); });