@aiam/ciba 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/ciba.mjs +8 -29
  2. package/package.json +1 -1
package/ciba.mjs CHANGED
@@ -12,7 +12,7 @@
12
12
  * ciba status Show session state
13
13
  */
14
14
  import { createECDH, createHash, createDecipheriv, createSign, createPrivateKey, randomBytes } from 'node:crypto';
15
- import { exec, spawn } from 'node:child_process';
15
+ import { exec, execFileSync, spawn } from 'node:child_process';
16
16
  import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
17
17
  import { createServer, createConnection } from 'node:net';
18
18
  import { homedir, hostname } from 'node:os';
@@ -439,22 +439,10 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
439
439
  const requests = deviceDoc.getMap('requests');
440
440
  const resourcesMap = deviceDoc.getMap('resources');
441
441
 
442
+ // Pass attrs straight through — server resolves grant_type from resource URN.
442
443
  const attrs = { ...(req.attrs || {}) };
443
- const resourceUrn = attrs.resource;
444
- if (!attrs.grant_type && typeof resourceUrn === 'string') {
445
- if (resourceUrn.startsWith('urn:sap:destination:')) {
446
- attrs.grant_type = 'urn:sap:destination';
447
- if (!attrs.destination) attrs.destination = resourceUrn.slice('urn:sap:destination:'.length);
448
- } else if (resourceUrn.startsWith('urn:sap:identity:') || resourceUrn.startsWith('urn:ietf:params:oauth:resource:')) {
449
- attrs.grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
450
- }
451
- }
452
-
453
444
  const defaultResource = `urn:sap:destination:${process.env.CIBA_DEFAULT_DESTINATION || 'WEBAGENTS_BACKEND'}`;
454
- const requestedResource =
455
- attrs.grant_type === 'urn:sap:destination' && attrs.destination
456
- ? `urn:sap:destination:${attrs.destination}`
457
- : attrs.resource ?? defaultResource;
445
+ const requestedResource = attrs.resource ?? defaultResource;
458
446
 
459
447
  const decryptFromTokenMap = (tokenMap) => {
460
448
  const ciphertext = tokenMap.get('ciphertext');
@@ -466,14 +454,8 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
466
454
  };
467
455
 
468
456
  if (req.command === 'refresh') {
469
- // Fire-and-forget: write the request, return immediately.
470
- // Server exchanges async; result lands on device doc via Yjs.
471
- // Default to the same resource as `ciba token` when none specified.
472
- if (!attrs.grant_type && !attrs.resource && !attrs.destination) {
473
- attrs.resource = `urn:sap:destination:${process.env.CIBA_DEFAULT_DESTINATION || 'WEBAGENTS_BACKEND'}`;
474
- attrs.grant_type = 'urn:sap:destination';
475
- attrs.destination = process.env.CIBA_DEFAULT_DESTINATION || 'WEBAGENTS_BACKEND';
476
- }
457
+ // Fire-and-forget just set default resource if none given.
458
+ if (!attrs.resource) attrs.resource = defaultResource;
477
459
  const newRid = randomBytes(8).toString('base64url');
478
460
  dlog(`refresh; writing requests[${newRid}] attrs=${JSON.stringify(attrs)}`);
479
461
  requests.set(newRid, { ...attrs, status: 'pending', created_at: new Date().toISOString() });
@@ -749,13 +731,10 @@ const stopCmd = defineCommand({
749
731
  meta: { description: 'Stop daemon and clear session' },
750
732
  args: {},
751
733
  async run() {
734
+ const cfg = loadConfig();
752
735
  if (cfg.pid) { try { process.kill(parseInt(cfg.pid)); } catch {} }
753
- // Kill all orphaned ciba daemon processes (previous --persist runs that
754
- // were never approved or whose parent exited without storing the PID).
755
- try {
756
- const { execFileSync } = await import('node:child_process');
757
- execFileSync('pkill', ['-f', 'ciba login --daemon'], { stdio: 'ignore' });
758
- } catch { /* pkill not found or no matching processes */ }
736
+ // Kill all orphaned ciba daemon processes.
737
+ try { execFileSync('pkill', ['-f', 'ciba login --daemon'], { stdio: 'ignore' }); } catch {}
759
738
  if (existsSync(SOCKET_PATH)) unlinkSync(SOCKET_PATH);
760
739
  const sessionFile = join(CONFIG_DIR, 'session');
761
740
  if (existsSync(sessionFile)) unlinkSync(sessionFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiam/ciba",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "OAuth 2.0 Device Authorization Grant CLI with cross-device push approval (Yjs sync, ECDH-encrypted token delivery, persistent device id)",
5
5
  "type": "module",
6
6
  "bin": {