@aiam/ciba 0.8.5 → 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.
- package/ciba.mjs +4 -22
- package/package.json +1 -1
package/ciba.mjs
CHANGED
|
@@ -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
|
|
470
|
-
|
|
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() });
|
package/package.json
CHANGED