feat(center): API-key agent auth

UserApiKey (apiKeyHash->userId); CLI 'user apikey --email'; POST
/auth/agent/login {apiKey} -> normal user session (api-key-guard exempt).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-15 16:52:42 +01:00
parent 3da51a60bc
commit dea946653b
7 changed files with 111 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ function getArg(flag: string): string | null {
function printUsageAndExit(): never {
console.error('Usage:');
console.error(' node dist/cli.js user create --email <email> --password <password>');
console.error(' node dist/cli.js user apikey --email <email> [--label <label>]');
console.error(' node dist/cli.js node register --node-id <id> --name <name> --endpoint <url>');
process.exit(1);
}
@@ -34,6 +35,17 @@ async function main() {
return;
}
if (subject === 'user' && action === 'apikey') {
const email = getArg('--email');
const label = getArg('--label');
if (!email) printUsageAndExit();
const auth = app.get(AuthService);
const res = await auth.createUserApiKey(email, label ?? undefined);
process.stdout.write(JSON.stringify({ ok: true, ...res }) + '\n');
return;
}
if (subject === 'node' && action === 'register') {
const nodeId = getArg('--node-id');
const name = getArg('--name');