@kya-os/mcp-i-cloudflare 1.12.4 → 1.13.2
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/README.md +5 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +23 -24
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +10 -5
- package/dist/app.js.map +1 -1
- package/dist/audit/assurance.d.ts +12 -0
- package/dist/audit/assurance.d.ts.map +1 -0
- package/dist/audit/assurance.js +21 -0
- package/dist/audit/assurance.js.map +1 -0
- package/dist/audit/deployment-binding.d.ts +513 -0
- package/dist/audit/deployment-binding.d.ts.map +1 -0
- package/dist/audit/deployment-binding.js +364 -0
- package/dist/audit/deployment-binding.js.map +1 -0
- package/dist/audit/durable-producer.d.ts +151 -0
- package/dist/audit/durable-producer.d.ts.map +1 -0
- package/dist/audit/durable-producer.js +953 -0
- package/dist/audit/durable-producer.js.map +1 -0
- package/dist/audit/verified-recorder-client.d.ts +34 -0
- package/dist/audit/verified-recorder-client.d.ts.map +1 -0
- package/dist/audit/verified-recorder-client.js +192 -0
- package/dist/audit/verified-recorder-client.js.map +1 -0
- package/dist/config.d.ts +4 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/delegation-http/pickup-routes.d.ts.map +1 -1
- package/dist/delegation-http/pickup-routes.js +36 -3
- package/dist/delegation-http/pickup-routes.js.map +1 -1
- package/dist/delegation-http/well-known-capability.d.ts +2 -1
- package/dist/delegation-http/well-known-capability.d.ts.map +1 -1
- package/dist/delegation-http/well-known-capability.js +2 -1
- package/dist/delegation-http/well-known-capability.js.map +1 -1
- package/dist/helpers/env-mapper.d.ts.map +1 -1
- package/dist/helpers/env-mapper.js +31 -0
- package/dist/helpers/env-mapper.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/invoke-tool-handler.d.ts +10 -0
- package/dist/runtime/invoke-tool-handler.d.ts.map +1 -0
- package/dist/runtime/invoke-tool-handler.js +11 -0
- package/dist/runtime/invoke-tool-handler.js.map +1 -0
- package/dist/runtime/oauth-handler.d.ts.map +1 -1
- package/dist/runtime/oauth-handler.js +12 -1
- package/dist/runtime/oauth-handler.js.map +1 -1
- package/dist/runtime/oidc/idp-scopes.d.ts +26 -0
- package/dist/runtime/oidc/idp-scopes.d.ts.map +1 -0
- package/dist/runtime/oidc/idp-scopes.js +24 -0
- package/dist/runtime/oidc/idp-scopes.js.map +1 -0
- package/dist/runtime.d.ts +1 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +72 -72
- package/dist/runtime.js.map +1 -1
- package/dist/services/batch-queue.d.ts +103 -0
- package/dist/services/batch-queue.d.ts.map +1 -0
- package/dist/services/batch-queue.js +180 -0
- package/dist/services/batch-queue.js.map +1 -0
- package/dist/services/consent-audit.service.d.ts +3 -10
- package/dist/services/consent-audit.service.d.ts.map +1 -1
- package/dist/services/consent-audit.service.js +44 -77
- package/dist/services/consent-audit.service.js.map +1 -1
- package/dist/services/consent.service.d.ts +7 -0
- package/dist/services/consent.service.d.ts.map +1 -1
- package/dist/services/consent.service.js +122 -69
- package/dist/services/consent.service.js.map +1 -1
- package/dist/services/kya-os-events.service.d.ts +131 -0
- package/dist/services/kya-os-events.service.d.ts.map +1 -0
- package/dist/services/kya-os-events.service.js +135 -0
- package/dist/services/kya-os-events.service.js.map +1 -0
- package/dist/services/proof-batch-queue.d.ts +15 -67
- package/dist/services/proof-batch-queue.d.ts.map +1 -1
- package/dist/services/proof-batch-queue.js +12 -147
- package/dist/services/proof-batch-queue.js.map +1 -1
- package/dist/services/proof.service.d.ts +7 -0
- package/dist/services/proof.service.d.ts.map +1 -1
- package/dist/services/proof.service.js +55 -4
- package/dist/services/proof.service.js.map +1 -1
- package/dist/services/vault-resolver.d.ts +0 -8
- package/dist/services/vault-resolver.d.ts.map +1 -1
- package/dist/services/vault-resolver.js +0 -22
- package/dist/services/vault-resolver.js.map +1 -1
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -6
- package/dist/runtime/audit-logger.d.ts +0 -96
- package/dist/runtime/audit-logger.d.ts.map +0 -1
- package/dist/runtime/audit-logger.js +0 -276
- package/dist/runtime/audit-logger.js.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Consent Audit Service
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Coordinates two independent consent lifecycle outputs:
|
|
5
|
+
* canonical audit trail events and proof submission.
|
|
6
6
|
*/
|
|
7
7
|
export class ConsentAuditService {
|
|
8
8
|
proofService;
|
|
9
|
-
auditLogger;
|
|
10
9
|
proofGenerator;
|
|
11
10
|
config;
|
|
12
11
|
runtime;
|
|
@@ -16,45 +15,22 @@ export class ConsentAuditService {
|
|
|
16
15
|
// TODO: Send to error tracking service
|
|
17
16
|
},
|
|
18
17
|
};
|
|
19
|
-
constructor(proofService,
|
|
18
|
+
constructor(proofService, proofGenerator, config, runtime // REQUIRED for identity
|
|
20
19
|
) {
|
|
21
20
|
this.proofService = proofService;
|
|
22
|
-
this.auditLogger = auditLogger;
|
|
23
21
|
this.proofGenerator = proofGenerator;
|
|
24
22
|
this.config = config;
|
|
25
23
|
this.runtime = runtime;
|
|
26
24
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Create a minimal SessionContext for audit logging
|
|
29
|
-
* Only sessionId and audience are used by logEvent, but TypeScript requires full SessionContext
|
|
30
|
-
*/
|
|
31
|
-
createSessionContext(sessionId) {
|
|
32
|
-
const now = Math.floor(Date.now() / 1000);
|
|
33
|
-
// Audience is typically from the handshake, but for consent events we use a default
|
|
34
|
-
const audience = "https://kya.vouched.id";
|
|
35
|
-
return {
|
|
36
|
-
sessionId,
|
|
37
|
-
audience,
|
|
38
|
-
nonce: "", // Not used by logEvent, but required by type
|
|
39
|
-
timestamp: now,
|
|
40
|
-
createdAt: now,
|
|
41
|
-
lastActivity: now,
|
|
42
|
-
ttlMinutes: 30,
|
|
43
|
-
identityState: "anonymous", // Phase 5: Default to anonymous
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
25
|
/**
|
|
47
26
|
* Log consent page view event
|
|
48
27
|
*/
|
|
49
28
|
async logConsentPageView(event) {
|
|
50
29
|
const timestamp = Math.floor(Date.now() / 1000); // Unix timestamp in seconds
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
identity,
|
|
56
|
-
session: this.createSessionContext(event.sessionId),
|
|
57
|
-
eventData: event,
|
|
30
|
+
await this.runtime.recordConsentAudit({
|
|
31
|
+
phase: "requested",
|
|
32
|
+
outcome: "succeeded",
|
|
33
|
+
sessionId: event.sessionId,
|
|
58
34
|
});
|
|
59
35
|
// Generate proof for dashboard
|
|
60
36
|
const proof = await this.generateConsentProof("consent:page_viewed", event, timestamp);
|
|
@@ -76,13 +52,12 @@ export class ConsentAuditService {
|
|
|
76
52
|
*/
|
|
77
53
|
async logConsentApproval(event) {
|
|
78
54
|
const timestamp = Math.floor(Date.now() / 1000); // Unix timestamp in seconds
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
eventData: event,
|
|
55
|
+
await this.runtime.recordConsentAudit({
|
|
56
|
+
phase: "approved",
|
|
57
|
+
outcome: "succeeded",
|
|
58
|
+
sessionId: event.sessionId,
|
|
59
|
+
userDid: event.userDid,
|
|
60
|
+
consentRef: event.delegationId,
|
|
86
61
|
});
|
|
87
62
|
// Generate proof
|
|
88
63
|
const proof = await this.generateConsentProof("consent:approved", event, timestamp);
|
|
@@ -108,13 +83,10 @@ export class ConsentAuditService {
|
|
|
108
83
|
*/
|
|
109
84
|
async logCredentialRequired(event) {
|
|
110
85
|
const timestamp = Math.floor(Date.now() / 1000); // Unix timestamp in seconds
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
identity,
|
|
116
|
-
session: this.createSessionContext(event.sessionId),
|
|
117
|
-
eventData: event,
|
|
86
|
+
await this.runtime.recordConsentAudit({
|
|
87
|
+
phase: "credential_required",
|
|
88
|
+
outcome: "challenged",
|
|
89
|
+
sessionId: event.sessionId,
|
|
118
90
|
});
|
|
119
91
|
// Generate proof
|
|
120
92
|
const proof = await this.generateConsentProof("consent:credential_required", event, timestamp);
|
|
@@ -143,13 +115,12 @@ export class ConsentAuditService {
|
|
|
143
115
|
*/
|
|
144
116
|
async logDelegationCreated(event) {
|
|
145
117
|
const timestamp = Math.floor(Date.now() / 1000); // Unix timestamp in seconds
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
eventData: event,
|
|
118
|
+
await this.runtime.recordDelegationAudit({
|
|
119
|
+
phase: "issued",
|
|
120
|
+
outcome: "succeeded",
|
|
121
|
+
sessionId: event.sessionId,
|
|
122
|
+
userDid: event.userDid,
|
|
123
|
+
delegationRef: event.delegationId,
|
|
153
124
|
});
|
|
154
125
|
// Generate proof
|
|
155
126
|
const proof = await this.generateConsentProof("consent:delegation_created", event, timestamp);
|
|
@@ -174,12 +145,11 @@ export class ConsentAuditService {
|
|
|
174
145
|
*/
|
|
175
146
|
async logCredentialAuthSuccess(event) {
|
|
176
147
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
eventData: event,
|
|
148
|
+
await this.runtime.recordConsentAudit({
|
|
149
|
+
phase: "credential_verified",
|
|
150
|
+
outcome: "succeeded",
|
|
151
|
+
sessionId: event.sessionId,
|
|
152
|
+
userDid: event.userDid,
|
|
183
153
|
});
|
|
184
154
|
const proof = await this.generateConsentProof("auth:credential_success", event, timestamp);
|
|
185
155
|
await this.proofService.submitProof(proof, {
|
|
@@ -203,12 +173,11 @@ export class ConsentAuditService {
|
|
|
203
173
|
*/
|
|
204
174
|
async logCredentialAuthFailed(event) {
|
|
205
175
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
eventData: event,
|
|
176
|
+
await this.runtime.recordConsentAudit({
|
|
177
|
+
phase: "credential_failed",
|
|
178
|
+
outcome: "failed",
|
|
179
|
+
sessionId: event.sessionId,
|
|
180
|
+
reasonCode: "CREDENTIAL_AUTH_FAILED",
|
|
212
181
|
});
|
|
213
182
|
const proof = await this.generateConsentProof("auth:credential_failed", event, timestamp);
|
|
214
183
|
await this.proofService.submitProof(proof, {
|
|
@@ -230,12 +199,11 @@ export class ConsentAuditService {
|
|
|
230
199
|
*/
|
|
231
200
|
async logOAuthSuccess(event) {
|
|
232
201
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
eventData: event,
|
|
202
|
+
await this.runtime.recordConsentAudit({
|
|
203
|
+
phase: "credential_verified",
|
|
204
|
+
outcome: "succeeded",
|
|
205
|
+
sessionId: event.sessionId,
|
|
206
|
+
userDid: event.userDid,
|
|
239
207
|
});
|
|
240
208
|
const proof = await this.generateConsentProof("auth:oauth_success", event, timestamp);
|
|
241
209
|
await this.proofService.submitProof(proof, {
|
|
@@ -259,12 +227,11 @@ export class ConsentAuditService {
|
|
|
259
227
|
*/
|
|
260
228
|
async logOAuthFailed(event) {
|
|
261
229
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
eventData: event,
|
|
230
|
+
await this.runtime.recordConsentAudit({
|
|
231
|
+
phase: "credential_failed",
|
|
232
|
+
outcome: "failed",
|
|
233
|
+
sessionId: event.sessionId,
|
|
234
|
+
reasonCode: "OAUTH_FAILED",
|
|
268
235
|
});
|
|
269
236
|
const proof = await this.generateConsentProof("auth:oauth_failed", event, timestamp);
|
|
270
237
|
await this.proofService.submitProof(proof, {
|
|
@@ -354,7 +321,7 @@ export class ConsentAuditService {
|
|
|
354
321
|
this.logger.error("Failed to get server identity", {
|
|
355
322
|
error: error instanceof Error ? error.message : String(error),
|
|
356
323
|
});
|
|
357
|
-
throw new Error("Server identity required for consent
|
|
324
|
+
throw new Error("Server identity required for consent proof generation");
|
|
358
325
|
}
|
|
359
326
|
}
|
|
360
327
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consent-audit.service.js","sourceRoot":"","sources":["../../src/services/consent-audit.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"consent-audit.service.js","sourceRoot":"","sources":["../../src/services/consent-audit.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,MAAM,OAAO,mBAAmB;IASpB;IACA;IACA;IACA;IAXF,MAAM,GAAG;QACf,KAAK,EAAE,CAAC,OAAe,EAAE,IAAyB,EAAE,EAAE;YACpD,OAAO,CAAC,KAAK,CAAC,yBAAyB,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;YACxD,uCAAuC;QACzC,CAAC;KACF,CAAC;IAEF,YACU,YAA0B,EAC1B,cAAwC,EACxC,MAA+B,EAC/B,OAA0B,CAAC,wBAAwB;;QAHnD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,mBAAc,GAAd,cAAc,CAA0B;QACxC,WAAM,GAAN,MAAM,CAAyB;QAC/B,YAAO,GAAP,OAAO,CAAmB;IACjC,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,kBAAkB,CAAC,KAMxB;QACC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,4BAA4B;QAC7E,M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CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBACjD,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CAAC;YACH,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -384,6 +384,13 @@ export declare class ConsentService {
|
|
|
384
384
|
* @returns Parsed body object
|
|
385
385
|
*/
|
|
386
386
|
private parseRequestBody;
|
|
387
|
+
/**
|
|
388
|
+
* Interpret the `CONSENT_REQUIRE_IDENTITY` env override that gates the
|
|
389
|
+
* identity-required refusal in `handleApproval`. Defaults to enabled - only
|
|
390
|
+
* an explicit `"false"`/`"0"` disables it, mirroring the escape-hatch
|
|
391
|
+
* convention used for `MCPI_HTTP_CHALLENGE` in config.ts.
|
|
392
|
+
*/
|
|
393
|
+
private isIdentityRequired;
|
|
387
394
|
/**
|
|
388
395
|
* Handle consent approval
|
|
389
396
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consent.service.d.ts","sourceRoot":"","sources":["../../src/services/consent.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"consent.service.d.ts","sour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;OAWG;YACW,2BAA2B;IAmDzC;;;;;;;;;OASG;IACU,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBzE;;;;;OAKG;YACW,eAAe;IAgB7B;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;YACW,sBAAsB;IAmJpC;;;;;;;;;OASG;IACH,OAAO,CAAC,WAAW;IAMnB;;;;;;;;;OASG;IACH,OAAO,CAAC,4BAA4B;IAqLpC;;OAEG;YACW,UAAU;IAqDxB;;;;;OAKG;YACW,WAAW;IA0GzB;;OAEG;YACW,qBAAqB;CAsBpC"}
|
|
@@ -12,6 +12,7 @@ import { DEFAULT_AGENTSHIELD_URL, DEFAULT_SESSION_CACHE_TTL, KEY_PAIR_TTL_SECOND
|
|
|
12
12
|
import { STORAGE_KEYS } from "../constants/storage-keys";
|
|
13
13
|
import { loadDay0Config, getDelegationFieldName } from "../utils/day0-config";
|
|
14
14
|
import { buildProviderAuthorizeUrl } from "../runtime/oidc/authorize-url.js";
|
|
15
|
+
import { resolveIdpScopes } from "../runtime/oidc/idp-scopes.js";
|
|
15
16
|
import { validateConsentApprovalRequest, } from "@kya-os/contracts/consent";
|
|
16
17
|
import { AGENTSHIELD_ENDPOINTS, createDelegationAPIResponseSchema, createDelegationResponseSchema, } from "@kya-os/contracts/agentshield-api";
|
|
17
18
|
import { createUnsignedVCJWT, completeVCJWT, parseVCJWT, generateDidKeyFromBase64, createDelegationVerifier, createDidKeyResolver, logger, base64urlEncodeFromBytes, base64urlDecodeToBytes, bytesToBase64, wrapDelegationAsVC, } from "@kya-os/mcp";
|
|
@@ -168,14 +169,10 @@ export class ConsentService {
|
|
|
168
169
|
const identity = await this.runtime.getIdentity();
|
|
169
170
|
// ✅ FIXED: CloudflareProofGenerator only takes identity, not providers
|
|
170
171
|
const proofGenerator = new CloudflareProofGenerator(identity);
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
// Create audit service with fetched config
|
|
178
|
-
this.auditService = new ConsentAuditService(new ProofService(config, this.runtime), auditLogger, proofGenerator, config, // ✅ Config fetched from remote API
|
|
172
|
+
// Proof submission and canonical audit delivery are independent. The
|
|
173
|
+
// lifecycle service submits proofs whenever proofing is enabled and
|
|
174
|
+
// records events only when the runtime has an auditTrail configured.
|
|
175
|
+
this.auditService = new ConsentAuditService(new ProofService(config, this.runtime), proofGenerator, config, // ✅ Config fetched from remote API
|
|
179
176
|
this.runtime);
|
|
180
177
|
logger.debug("[ConsentService] Audit service initialized successfully");
|
|
181
178
|
}
|
|
@@ -1158,13 +1155,19 @@ export class ConsentService {
|
|
|
1158
1155
|
!providerConfig.proxyMode) {
|
|
1159
1156
|
// Use providerConfig.clientId from AgentShield dashboard config
|
|
1160
1157
|
const oauthClientId = providerConfig.clientId || projectId;
|
|
1158
|
+
// The `scopes` argument holds MCP-I delegation scopes (e.g. "greet:execute"),
|
|
1159
|
+
// which the identity provider has never heard of. Only the provider's own
|
|
1160
|
+
// scopes belong in its authorization URL; delegation scopes already travel
|
|
1161
|
+
// separately in `stateData.scopes` above, for the callback to mint the
|
|
1162
|
+
// delegation.
|
|
1163
|
+
const idpScopes = resolveIdpScopes(providerConfig);
|
|
1161
1164
|
logger.debug("[ConsentService] Using direct OAuth mode (PKCE)", {
|
|
1162
1165
|
provider: provider || "unknown",
|
|
1163
1166
|
authorizationUrl: providerConfig.authorizationUrl,
|
|
1164
1167
|
supportsPKCE: providerConfig.supportsPKCE,
|
|
1165
1168
|
clientId: oauthClientId.substring(0, 8) + "...",
|
|
1166
1169
|
});
|
|
1167
|
-
return this.buildDirectOAuthUrl(providerConfig, oauthClientId, `${serverUrl}/oauth/callback`,
|
|
1170
|
+
return this.buildDirectOAuthUrl(providerConfig, oauthClientId, `${serverUrl}/oauth/callback`, idpScopes, stateParam, codeChallenge);
|
|
1168
1171
|
}
|
|
1169
1172
|
// Phase 3: Validate custom parameters don't conflict with reserved parameters
|
|
1170
1173
|
const RESERVED_PARAMS = [
|
|
@@ -1199,7 +1202,9 @@ export class ConsentService {
|
|
|
1199
1202
|
oauthUrl.searchParams.set("response_type", "code");
|
|
1200
1203
|
oauthUrl.searchParams.set("client_id", projectId); // Use projectId as client_id
|
|
1201
1204
|
oauthUrl.searchParams.set("redirect_uri", `${serverUrl}/oauth/callback`);
|
|
1202
|
-
|
|
1205
|
+
// Same separation as the direct-PKCE branch above: `scopes` is the MCP-I
|
|
1206
|
+
// delegation scopes, not what belongs in the IdP-facing `scope` param.
|
|
1207
|
+
oauthUrl.searchParams.set("scope", resolveIdpScopes(providerConfig).join(" "));
|
|
1203
1208
|
oauthUrl.searchParams.set("state", stateParam);
|
|
1204
1209
|
// ✅ Pass provider to AgentShield bouncer so it selects the correct auth method
|
|
1205
1210
|
// This is critical when multiple providers are configured for a project
|
|
@@ -3223,6 +3228,19 @@ export class ConsentService {
|
|
|
3223
3228
|
throw new Error(`Failed to parse request body: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3224
3229
|
}
|
|
3225
3230
|
}
|
|
3231
|
+
/**
|
|
3232
|
+
* Interpret the `CONSENT_REQUIRE_IDENTITY` env override that gates the
|
|
3233
|
+
* identity-required refusal in `handleApproval`. Defaults to enabled - only
|
|
3234
|
+
* an explicit `"false"`/`"0"` disables it, mirroring the escape-hatch
|
|
3235
|
+
* convention used for `MCPI_HTTP_CHALLENGE` in config.ts.
|
|
3236
|
+
*/
|
|
3237
|
+
isIdentityRequired() {
|
|
3238
|
+
const raw = this.env.CONSENT_REQUIRE_IDENTITY;
|
|
3239
|
+
if (raw === undefined || raw === null)
|
|
3240
|
+
return true;
|
|
3241
|
+
const normalized = String(raw).trim().toLowerCase();
|
|
3242
|
+
return normalized !== "false" && normalized !== "0";
|
|
3243
|
+
}
|
|
3226
3244
|
/**
|
|
3227
3245
|
* Handle consent approval
|
|
3228
3246
|
*
|
|
@@ -3457,11 +3475,30 @@ export class ConsentService {
|
|
|
3457
3475
|
// ✅ Lazy initialization with projectId
|
|
3458
3476
|
const auditService = await this.getAuditService(projectId);
|
|
3459
3477
|
// Check if user needs credentials before delegation
|
|
3460
|
-
// Skip credential requirement for consent-only mode (provider_type: 'none')
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3478
|
+
// Skip credential requirement for consent-only mode (provider_type: 'none').
|
|
3479
|
+
// Read the EFFECTIVE provider_type off bodyObj, not the `providerType`
|
|
3480
|
+
// captured above: the post-OAuth/post-credential clickwrap branches above
|
|
3481
|
+
// rewrite bodyObj.provider_type to 'oauth'/'password' while `providerType`
|
|
3482
|
+
// stays the original raw 'none'. Gating on the stale value would treat
|
|
3483
|
+
// those already-authenticated clickwrap submissions as consent-only and
|
|
3484
|
+
// skip the identity check entirely.
|
|
3485
|
+
const effectiveProviderType = bodyObj.provider_type;
|
|
3486
|
+
const isConsentOnlyMode = effectiveProviderType === CONSENT_PROVIDER_TYPES.NONE;
|
|
3487
|
+
// Resolve identity once, ahead of the gate below, using the same priority
|
|
3488
|
+
// createDelegation used to apply internally (request.user_did first, then
|
|
3489
|
+
// session lookup). The resolved value is threaded into createDelegation so
|
|
3490
|
+
// it is never resolved a second time.
|
|
3491
|
+
let resolvedUserDid = approvalRequest.user_did;
|
|
3492
|
+
if (!resolvedUserDid && approvalRequest.session_id) {
|
|
3493
|
+
try {
|
|
3494
|
+
resolvedUserDid =
|
|
3495
|
+
(await this.getUserDidForSession(approvalRequest.session_id, approvalRequest.oauth_identity || undefined)) ?? undefined;
|
|
3496
|
+
}
|
|
3497
|
+
catch (error) {
|
|
3498
|
+
logger.debug("[ConsentService] Failed to resolve userDid ahead of identity gate:", error);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
const needsCredentials = !isConsentOnlyMode && !resolvedUserDid;
|
|
3465
3502
|
if (needsCredentials && auditService) {
|
|
3466
3503
|
await auditService
|
|
3467
3504
|
.logCredentialRequired({
|
|
@@ -3479,12 +3516,25 @@ export class ConsentService {
|
|
|
3479
3516
|
error: err instanceof Error ? err.message : String(err),
|
|
3480
3517
|
});
|
|
3481
3518
|
});
|
|
3482
|
-
|
|
3483
|
-
|
|
3519
|
+
}
|
|
3520
|
+
// Fail closed: an authenticated-provider approval with no resolvable user
|
|
3521
|
+
// identity must not mint a delegation. Consent-only mode is exempt - it
|
|
3522
|
+
// legitimately has no user identity. Gated on CONSENT_REQUIRE_IDENTITY so
|
|
3523
|
+
// a bad interaction can be switched off in production without a redeploy;
|
|
3524
|
+
// defaults to enabled.
|
|
3525
|
+
if (needsCredentials && this.isIdentityRequired()) {
|
|
3526
|
+
return new Response(JSON.stringify({
|
|
3527
|
+
success: false,
|
|
3528
|
+
error: "User identity is required to approve this request",
|
|
3529
|
+
error_code: "identity_required",
|
|
3530
|
+
}), {
|
|
3531
|
+
status: 403,
|
|
3532
|
+
headers: { "Content-Type": "application/json" },
|
|
3533
|
+
});
|
|
3484
3534
|
}
|
|
3485
3535
|
// Create delegation via AgentShield API
|
|
3486
3536
|
logger.debug("[ConsentService] Creating delegation...");
|
|
3487
|
-
const delegationResult = await this.createDelegation(approvalRequest, resolveExpirationDays(consentConfig.expirationDays));
|
|
3537
|
+
const delegationResult = await this.createDelegation(approvalRequest, resolveExpirationDays(consentConfig.expirationDays), resolvedUserDid ?? null);
|
|
3488
3538
|
if (!delegationResult.success) {
|
|
3489
3539
|
logger.error("[ConsentService] Delegation creation failed:", {
|
|
3490
3540
|
error: delegationResult.error,
|
|
@@ -3511,19 +3561,9 @@ export class ConsentService {
|
|
|
3511
3561
|
// ✅ After successful delegation creation - log audit events
|
|
3512
3562
|
if (auditService && delegationResult.success) {
|
|
3513
3563
|
try {
|
|
3514
|
-
//
|
|
3515
|
-
//
|
|
3516
|
-
|
|
3517
|
-
if (approvalRequest.session_id) {
|
|
3518
|
-
try {
|
|
3519
|
-
userDid =
|
|
3520
|
-
(await this.getUserDidForSession(approvalRequest.session_id, approvalRequest.oauth_identity || undefined)) ?? undefined; // Phase 5: Convert null to undefined
|
|
3521
|
-
}
|
|
3522
|
-
catch (error) {
|
|
3523
|
-
logger.warn("[ConsentService] Failed to get userDid for audit logging:", error);
|
|
3524
|
-
// Continue without userDid - audit events can still be logged
|
|
3525
|
-
}
|
|
3526
|
-
}
|
|
3564
|
+
// Reuse the identity resolved ahead of the gate above - do not
|
|
3565
|
+
// read KV a second time for the same session.
|
|
3566
|
+
const userDid = resolvedUserDid;
|
|
3527
3567
|
await auditService.logConsentApproval({
|
|
3528
3568
|
sessionId: approvalRequest.session_id,
|
|
3529
3569
|
userDid,
|
|
@@ -3587,7 +3627,7 @@ export class ConsentService {
|
|
|
3587
3627
|
* @param request - Approval request
|
|
3588
3628
|
* @returns Delegation creation result
|
|
3589
3629
|
*/
|
|
3590
|
-
async createDelegation(request, expirationDaysOverride) {
|
|
3630
|
+
async createDelegation(request, expirationDaysOverride, resolvedUserDid) {
|
|
3591
3631
|
const agentShieldUrl = this.env.AGENTSHIELD_API_URL || DEFAULT_AGENTSHIELD_URL;
|
|
3592
3632
|
const apiKey = this.env.AGENTSHIELD_API_KEY;
|
|
3593
3633
|
if (!apiKey) {
|
|
@@ -3602,46 +3642,59 @@ export class ConsentService {
|
|
|
3602
3642
|
// Load Day0 configuration to determine field name and API capabilities
|
|
3603
3643
|
await loadDay0Config(this.env.DELEGATION_STORAGE);
|
|
3604
3644
|
const fieldName = await getDelegationFieldName(this.env.DELEGATION_STORAGE);
|
|
3605
|
-
// Get userDID
|
|
3606
|
-
//
|
|
3607
|
-
//
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
if (
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
hasOAuthIdentity: !!request.oauth_identity,
|
|
3615
|
-
oauthProvider: request.oauth_identity?.provider,
|
|
3616
|
-
hasStorage: !!this.env.DELEGATION_STORAGE,
|
|
3617
|
-
});
|
|
3618
|
-
// Pass OAuth identity if available in approval request (can be null/undefined)
|
|
3619
|
-
// getUserDidForSession can work without DELEGATION_STORAGE (uses in-memory UserDidManager)
|
|
3620
|
-
// Phase 5: Returns null if no identity found (session stays anonymous)
|
|
3621
|
-
userDid =
|
|
3622
|
-
(await this.getUserDidForSession(request.session_id, request.oauth_identity || undefined // Explicitly handle null as undefined
|
|
3623
|
-
)) ?? undefined;
|
|
3624
|
-
logger.debug("[ConsentService] User DID retrieved from storage:", {
|
|
3625
|
-
userDid: userDid?.substring(0, 20) + "...",
|
|
3626
|
-
hasUserDid: !!userDid,
|
|
3627
|
-
});
|
|
3628
|
-
}
|
|
3629
|
-
catch (error) {
|
|
3630
|
-
logger.debug("[ConsentService] Failed to get/generate userDid:", error);
|
|
3631
|
-
// Continue without userDid - delegation will work without user_identifier
|
|
3632
|
-
// This is valid for non-OAuth scenarios, but we should log this as a warning
|
|
3633
|
-
logger.warn("[ConsentService] Delegation will be created without user_identifier - this may affect user tracking");
|
|
3634
|
-
}
|
|
3635
|
-
}
|
|
3636
|
-
else if (userDid) {
|
|
3637
|
-
// userDid was provided in request (e.g., from credential auth flow)
|
|
3638
|
-
logger.debug("[ConsentService] Using provided user_did from request:", {
|
|
3639
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
3640
|
-
source: "request.user_did",
|
|
3645
|
+
// Get userDID. If the caller (handleApproval) already resolved it, use that
|
|
3646
|
+
// directly and skip the lookup below entirely - it was already attempted
|
|
3647
|
+
// with the same priority (request.user_did first, then session storage),
|
|
3648
|
+
// and repeating it would read KV a second time for no benefit.
|
|
3649
|
+
let userDid;
|
|
3650
|
+
if (resolvedUserDid !== undefined) {
|
|
3651
|
+
userDid = resolvedUserDid ?? undefined;
|
|
3652
|
+
logger.debug("[ConsentService] Using pre-resolved userDid:", {
|
|
3653
|
+
hasUserDid: !!userDid,
|
|
3641
3654
|
});
|
|
3642
3655
|
}
|
|
3643
3656
|
else {
|
|
3644
|
-
|
|
3657
|
+
// FIRST check if passed in request, THEN fallback to session storage
|
|
3658
|
+
// request.user_did takes priority to avoid KV eventual consistency issues
|
|
3659
|
+
// This fixes the bug where credential auth resolves userDid but it's not found in storage
|
|
3660
|
+
userDid = request.user_did;
|
|
3661
|
+
// Only fetch from storage if not already provided in request
|
|
3662
|
+
if (!userDid && request.session_id) {
|
|
3663
|
+
try {
|
|
3664
|
+
logger.debug("[ConsentService] Getting User DID for session:", {
|
|
3665
|
+
sessionId: request.session_id.substring(0, 20) + "...",
|
|
3666
|
+
hasOAuthIdentity: !!request.oauth_identity,
|
|
3667
|
+
oauthProvider: request.oauth_identity?.provider,
|
|
3668
|
+
hasStorage: !!this.env.DELEGATION_STORAGE,
|
|
3669
|
+
});
|
|
3670
|
+
// Pass OAuth identity if available in approval request (can be null/undefined)
|
|
3671
|
+
// getUserDidForSession can work without DELEGATION_STORAGE (uses in-memory UserDidManager)
|
|
3672
|
+
// Phase 5: Returns null if no identity found (session stays anonymous)
|
|
3673
|
+
userDid =
|
|
3674
|
+
(await this.getUserDidForSession(request.session_id, request.oauth_identity || undefined // Explicitly handle null as undefined
|
|
3675
|
+
)) ?? undefined;
|
|
3676
|
+
logger.debug("[ConsentService] User DID retrieved from storage:", {
|
|
3677
|
+
userDid: userDid?.substring(0, 20) + "...",
|
|
3678
|
+
hasUserDid: !!userDid,
|
|
3679
|
+
});
|
|
3680
|
+
}
|
|
3681
|
+
catch (error) {
|
|
3682
|
+
logger.debug("[ConsentService] Failed to get/generate userDid:", error);
|
|
3683
|
+
// Continue without userDid - delegation will work without user_identifier
|
|
3684
|
+
// This is valid for non-OAuth scenarios, but we should log this as a warning
|
|
3685
|
+
logger.warn("[ConsentService] Delegation will be created without user_identifier - this may affect user tracking");
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
else if (userDid) {
|
|
3689
|
+
// userDid was provided in request (e.g., from credential auth flow)
|
|
3690
|
+
logger.debug("[ConsentService] Using provided user_did from request:", {
|
|
3691
|
+
userDid: userDid.substring(0, 20) + "...",
|
|
3692
|
+
source: "request.user_did",
|
|
3693
|
+
});
|
|
3694
|
+
}
|
|
3695
|
+
else {
|
|
3696
|
+
logger.debug("[ConsentService] No session_id provided - skipping User DID generation");
|
|
3697
|
+
}
|
|
3645
3698
|
}
|
|
3646
3699
|
const expiresInDays = expirationDaysOverride ?? DEFAULT_EXPIRATION_DAYS;
|
|
3647
3700
|
// Phase 2 VC-Only: Issue Delegation VC if we have a session and userDid
|