feat(server): handshake token pour un shell embarquant le daemon (app de bureau)
Dans runDaemon, si ARBORETUM_EMIT_TOKEN_FD est fourni, mint un token 'desktop' et l'écrit en JSON {token,url} sur ce descripteur (pipe stdio privé parent-enfant). Additif et gardé : sans la variable, comportement strictement inchangé. Permettra à l'app Electron d'ouvrir la SPA déjà authentifiée sans écran de login. Vérifié (handshake OK), 431 tests.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync, writeSync } from 'node:fs';
|
||||||
import { join, dirname } from 'node:path';
|
import { join, dirname } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { loadConfig, type Config } from './config.js';
|
import { loadConfig, type Config } from './config.js';
|
||||||
@@ -48,6 +48,20 @@ export async function runDaemon(config: Config): Promise<void> {
|
|||||||
console.log('Tokens are stored hashed and cannot be re-printed. Create a new one from Settings (or reset the db).');
|
console.log('Tokens are stored hashed and cannot be re-printed. Create a new one from Settings (or reset the db).');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handshake pour un shell embarquant le daemon (app de bureau) : si ARBORETUM_EMIT_TOKEN_FD est
|
||||||
|
// fourni, on mint un token frais et on l'écrit en JSON sur ce descripteur (pipe stdio privé
|
||||||
|
// parent<->enfant). Additif : sans cette variable, comportement strictement inchangé. Le token ne
|
||||||
|
// transite jamais par le renderer et n'est pas affiché.
|
||||||
|
const emitFd = process.env.ARBORETUM_EMIT_TOKEN_FD;
|
||||||
|
if (emitFd) {
|
||||||
|
try {
|
||||||
|
const token = auth.createToken('desktop');
|
||||||
|
writeSync(Number(emitFd), `${JSON.stringify({ token, url })}\n`);
|
||||||
|
} catch (err) {
|
||||||
|
app.log.warn(`token handshake failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let shuttingDown = false;
|
let shuttingDown = false;
|
||||||
const shutdown = (signal: string): void => {
|
const shutdown = (signal: string): void => {
|
||||||
if (shuttingDown) return;
|
if (shuttingDown) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user