@payware/mcp-server 1.3.1 → 1.3.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/package.json
CHANGED
|
@@ -76,7 +76,7 @@ export function generateSandboxConfig(partnerId, privateKey = null) {
|
|
|
76
76
|
type: 'JWT',
|
|
77
77
|
algorithm: 'RS256',
|
|
78
78
|
audience: 'https://payware.eu',
|
|
79
|
-
|
|
79
|
+
requiresContentSha256: 'For POST/PUT/PATCH requests: Base64(SHA-256(body)) in the JWT header',
|
|
80
80
|
hasPrivateKey: !!privateKey
|
|
81
81
|
},
|
|
82
82
|
generatedAt: new Date().toISOString()
|
|
@@ -30,26 +30,6 @@ export function generateContentSha256(body) {
|
|
|
30
30
|
return hash.digest('base64');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* Generate MD5 hash for JWT contentMd5 header (DEPRECATED - use generateContentSha256)
|
|
35
|
-
*
|
|
36
|
-
* @deprecated Use generateContentSha256 instead. MD5 is still supported by the server
|
|
37
|
-
* for backwards compatibility but is deprecated.
|
|
38
|
-
*
|
|
39
|
-
* @param {Object|string} body - Request body (object will be consistently serialized)
|
|
40
|
-
* @returns {string} Base64 encoded MD5 hash for JWT contentMd5 header
|
|
41
|
-
*/
|
|
42
|
-
export function generateContentMd5(body) {
|
|
43
|
-
if (!body) return null;
|
|
44
|
-
|
|
45
|
-
const bodyString = typeof body === 'string' ? body : createDeterministicJSON(body);
|
|
46
|
-
|
|
47
|
-
// Generate MD5 hash as raw binary and encode in base64
|
|
48
|
-
const hash = crypto.createHash('md5');
|
|
49
|
-
hash.update(bodyString, 'utf8');
|
|
50
|
-
return hash.digest('base64');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
33
|
/**
|
|
54
34
|
* Generate the exact JSON string for both JWT content hash and HTTP request body
|
|
55
35
|
*
|
|
@@ -143,9 +123,16 @@ export function createRequestSignature(method, path, body, privateKey) {
|
|
|
143
123
|
/**
|
|
144
124
|
* Validate and debug JWT token implementation
|
|
145
125
|
*/
|
|
126
|
+
// The rules below mirror the payware API's authentication checks. A check that is looser
|
|
127
|
+
// than the server's reports a token as valid that the API refuses; one that is stricter fails tokens the
|
|
128
|
+
// API accepts - the audience check did both kinds of harm until it learned the on-behalf form.
|
|
129
|
+
const PAYWARE_AUDIENCE = 'https://payware.eu';
|
|
130
|
+
const IAT_MAX_AGE_SECONDS = 300;
|
|
131
|
+
const IAT_MAX_FUTURE_SKEW_SECONDS = 60;
|
|
132
|
+
|
|
146
133
|
export const validateJWTTokenTool = {
|
|
147
134
|
name: "payware_authentication_validate_jwt",
|
|
148
|
-
description: "Validate and debug
|
|
135
|
+
description: "Validate and debug a payware JWT: decode header and payload, check the claims against the API's rules (algorithm, audience including the ISV on-behalf form, 5-minute freshness), and verify the contentSha256 hash against the request body when one is given",
|
|
149
136
|
inputSchema: {
|
|
150
137
|
type: "object",
|
|
151
138
|
properties: {
|
|
@@ -155,7 +142,7 @@ export const validateJWTTokenTool = {
|
|
|
155
142
|
},
|
|
156
143
|
expectedPayload: {
|
|
157
144
|
type: "object",
|
|
158
|
-
description: "
|
|
145
|
+
description: "The request body the token was made for (optional). Give it for POST, PUT and PATCH: contentSha256 is then required and checked against it. Leave it out for GET and DELETE, which carry no hash."
|
|
159
146
|
}
|
|
160
147
|
},
|
|
161
148
|
required: ["jwtToken"],
|
|
@@ -179,55 +166,76 @@ export const validateJWTTokenTool = {
|
|
|
179
166
|
|
|
180
167
|
const { header, payload } = decoded;
|
|
181
168
|
|
|
182
|
-
//
|
|
169
|
+
// Only contentSha256 counts. The server stopped accepting contentMd5 (SEC-013): a token that
|
|
170
|
+
// carries only contentMd5 is answered 401 ERR_MISSING_CONTENT_HASH, so reporting it here as a
|
|
171
|
+
// present, matching hash told an integrator a token was fine that the API would refuse.
|
|
183
172
|
const hasContentSha256 = !!header.contentSha256;
|
|
184
173
|
const hasContentMd5 = !!header.contentMd5;
|
|
185
|
-
const hasContentHash = hasContentSha256
|
|
174
|
+
const hasContentHash = hasContentSha256;
|
|
175
|
+
|
|
176
|
+
// Audience. https://payware.eu for a direct call, and always on /oauth2. An ISV acting on behalf
|
|
177
|
+
// of a merchant sets aud to that merchant's partner ID and must then carry sub = the merchant's
|
|
178
|
+
// OAuth token - the server answers ERR_MISSING_TOKEN without it. Only accepting
|
|
179
|
+
// https://payware.eu failed every on-behalf token, which is most of what an ISV sends.
|
|
180
|
+
const onBehalf = typeof payload.aud === 'string' && payload.aud !== '' && payload.aud !== PAYWARE_AUDIENCE;
|
|
181
|
+
const hasSubject = typeof payload.sub === 'string' && payload.sub.trim() !== '';
|
|
182
|
+
|
|
183
|
+
// Freshness. The server refuses a token issued more than 5 minutes ago, or more than 60 seconds
|
|
184
|
+
// in the future (ERR_STALE_TOKEN); a missing iat is reported by issuedAt.
|
|
185
|
+
const ageSeconds = payload.iat ? Math.floor(Date.now() / 1000) - payload.iat : null;
|
|
186
|
+
const stale = ageSeconds !== null && ageSeconds > IAT_MAX_AGE_SECONDS;
|
|
187
|
+
const fromTheFuture = ageSeconds !== null && ageSeconds < -IAT_MAX_FUTURE_SKEW_SECONDS;
|
|
186
188
|
|
|
187
189
|
// Validation results
|
|
188
190
|
const validation = {
|
|
189
191
|
structure: true,
|
|
190
192
|
algorithm: header.alg === 'RS256',
|
|
191
193
|
type: header.typ === 'JWT',
|
|
192
|
-
audience: payload.aud ===
|
|
194
|
+
audience: payload.aud === PAYWARE_AUDIENCE || (onBehalf && hasSubject),
|
|
193
195
|
issuer: !!payload.iss,
|
|
194
196
|
issuedAt: !!payload.iat,
|
|
195
|
-
|
|
197
|
+
freshness: !stale && !fromTheFuture,
|
|
198
|
+
// Required only on a request with a body. Without expectedPayload this tool cannot tell a GET
|
|
199
|
+
// from a POST, so an absent hash is not a failure on its own - it used to fail every GET token
|
|
200
|
+
// while the report beside it said "OK for GET requests".
|
|
201
|
+
contentHash: expectedPayload ? hasContentHash : true
|
|
196
202
|
};
|
|
197
203
|
|
|
198
204
|
// Content hash validation if expected payload provided
|
|
199
205
|
let hashValidation = null;
|
|
200
206
|
if (expectedPayload && hasContentHash) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
};
|
|
210
|
-
} else if (hasContentMd5) {
|
|
211
|
-
const calculatedMd5 = generateContentMd5(expectedPayload);
|
|
212
|
-
hashValidation = {
|
|
213
|
-
type: 'MD5 (deprecated)',
|
|
214
|
-
provided: header.contentMd5,
|
|
215
|
-
calculated: calculatedMd5,
|
|
216
|
-
matches: header.contentMd5 === calculatedMd5,
|
|
217
|
-
deterministicJson: createDeterministicJSON(expectedPayload)
|
|
218
|
-
};
|
|
219
|
-
}
|
|
207
|
+
const calculatedSha256 = generateContentSha256(expectedPayload);
|
|
208
|
+
hashValidation = {
|
|
209
|
+
type: 'SHA-256',
|
|
210
|
+
provided: header.contentSha256,
|
|
211
|
+
calculated: calculatedSha256,
|
|
212
|
+
matches: header.contentSha256 === calculatedSha256,
|
|
213
|
+
deterministicJson: createDeterministicJSON(expectedPayload)
|
|
214
|
+
};
|
|
220
215
|
}
|
|
221
216
|
|
|
222
217
|
// Check for common issues
|
|
223
218
|
const issues = [];
|
|
224
219
|
if (!validation.algorithm) issues.push("Algorithm should be 'RS256'");
|
|
225
220
|
if (!validation.type) issues.push("Type should be 'JWT'");
|
|
226
|
-
if (!
|
|
221
|
+
if (!payload.aud) {
|
|
222
|
+
issues.push("Missing audience (aud) claim");
|
|
223
|
+
} else if (onBehalf && !hasSubject) {
|
|
224
|
+
issues.push(`aud is a merchant partner ID (${payload.aud}), which means acting on its behalf, but sub is missing - set sub to that merchant's OAuth token (ERR_MISSING_TOKEN), or use aud = ${PAYWARE_AUDIENCE} for a direct call`);
|
|
225
|
+
}
|
|
227
226
|
if (!validation.issuer) issues.push("Missing issuer (iss) claim");
|
|
228
227
|
if (!validation.issuedAt) issues.push("Missing issued at (iat) claim");
|
|
228
|
+
if (stale) {
|
|
229
|
+
issues.push(`Token is stale: issued ${ageSeconds}s ago, and the API accepts tokens up to ${IAT_MAX_AGE_SECONDS}s old (ERR_STALE_TOKEN)`);
|
|
230
|
+
}
|
|
231
|
+
if (fromTheFuture) {
|
|
232
|
+
issues.push(`iat is ${-ageSeconds}s in the future, beyond the ${IAT_MAX_FUTURE_SKEW_SECONDS}s of clock skew the API tolerates (ERR_STALE_TOKEN)`);
|
|
233
|
+
}
|
|
234
|
+
if (expectedPayload && !hasContentSha256 && !hasContentMd5) {
|
|
235
|
+
issues.push("Missing contentSha256: a request with a body must carry Base64(SHA-256(body)) in the JWT header (ERR_MISSING_CONTENT_HASH)");
|
|
236
|
+
}
|
|
229
237
|
if (hasContentMd5 && !hasContentSha256) {
|
|
230
|
-
issues.push("
|
|
238
|
+
issues.push("contentMd5 is not accepted: the API answers 401 ERR_MISSING_CONTENT_HASH. Send contentSha256 = Base64(SHA-256(body)) instead");
|
|
231
239
|
}
|
|
232
240
|
if (hashValidation && !hashValidation.matches) {
|
|
233
241
|
issues.push("Content hash mismatch - ensure deterministic JSON serialization with sorted keys");
|
|
@@ -259,10 +267,11 @@ ${JSON.stringify(payload, null, 2)}
|
|
|
259
267
|
${validation.structure ? '✅' : '❌'} **Structure**: JWT has valid 3-part structure
|
|
260
268
|
${validation.algorithm ? '✅' : '❌'} **Algorithm**: RS256 ${validation.algorithm ? '(correct)' : `(found: ${header.alg})`}
|
|
261
269
|
${validation.type ? '✅' : '❌'} **Type**: JWT ${validation.type ? '(correct)' : `(found: ${header.typ})`}
|
|
262
|
-
${validation.audience ? '✅' : '❌'} **Audience**:
|
|
270
|
+
${validation.audience ? '✅' : '❌'} **Audience**: ${payload.aud === PAYWARE_AUDIENCE ? `${PAYWARE_AUDIENCE} (direct call)` : onBehalf ? `${payload.aud} (on behalf of this merchant, sub ${hasSubject ? 'present' : 'MISSING'}; not valid on /oauth2 endpoints, which need ${PAYWARE_AUDIENCE})` : 'Missing'}
|
|
263
271
|
${validation.issuer ? '✅' : '❌'} **Issuer**: ${payload.iss || 'Missing'}
|
|
264
272
|
${validation.issuedAt ? '✅' : '❌'} **Issued At**: ${payload.iat ? new Date(payload.iat * 1000).toISOString() : 'Missing'}
|
|
265
|
-
${validation.
|
|
273
|
+
${validation.freshness ? '✅' : '❌'} **Freshness**: ${ageSeconds === null ? 'n/a' : stale ? `stale - ${ageSeconds}s old, limit ${IAT_MAX_AGE_SECONDS}s` : fromTheFuture ? `${-ageSeconds}s in the future, limit ${IAT_MAX_FUTURE_SKEW_SECONDS}s` : `${ageSeconds}s old (limit ${IAT_MAX_AGE_SECONDS}s)`}
|
|
274
|
+
${header.contentSha256 ? '✅' : validation.contentHash ? 'ℹ️' : '❌'} **Content Hash**: ${header.contentSha256 ? `SHA-256: ${header.contentSha256}` : header.contentMd5 ? `only contentMd5, which the API rejects - send contentSha256` : expectedPayload ? 'Missing - required on a request with a body' : 'Not present (fine for GET and DELETE; required on POST, PUT and PATCH with a body)'}
|
|
266
275
|
|
|
267
276
|
${hashValidation ? `## Content Hash Validation
|
|
268
277
|
|
|
@@ -305,7 +314,8 @@ ${issues.map(issue => `- ${issue}`).join('\n')}
|
|
|
305
314
|
|
|
306
315
|
${issues.includes("Algorithm should be 'RS256'") ? '- Update JWT algorithm to RS256\n' : ''}
|
|
307
316
|
${issues.includes("Type should be 'JWT'") ? '- Set JWT type to "JWT"\n' : ''}
|
|
308
|
-
${
|
|
317
|
+
${!validation.audience ? `- Set aud to "${PAYWARE_AUDIENCE}" for a direct call, or to the merchant's partner ID together with sub = its OAuth token when acting on its behalf\n` : ''}
|
|
318
|
+
${!validation.freshness ? '- Create the JWT immediately before each request: the API accepts it for 5 minutes, and check the clock of the machine that signs it\n' : ''}
|
|
309
319
|
${issues.includes("Missing issuer (iss) claim") ? '- Add your partner ID as the issuer claim\n' : ''}
|
|
310
320
|
${issues.includes("Missing issued at (iat) claim") ? '- Add current Unix timestamp as issued at claim\n' : ''}
|
|
311
321
|
${issues.some(i => i.includes('hash mismatch')) ? '- Use deterministic JSON serialization with sorted keys\n- Ensure same JSON string for hash calculation and HTTP body\n' : ''}
|
|
@@ -550,7 +560,7 @@ ${deterministicJson}
|
|
|
550
560
|
❌ Setting audience to "payware" instead of "https://payware.eu"
|
|
551
561
|
❌ Putting contentSha256 in payload instead of header
|
|
552
562
|
❌ Using wrong algorithm (HS256 instead of RS256)
|
|
553
|
-
❌
|
|
563
|
+
❌ Sending contentMd5 - the API no longer accepts it; use contentSha256
|
|
554
564
|
|
|
555
565
|
---
|
|
556
566
|
**Execution Info:**
|
|
@@ -350,7 +350,8 @@ ${rows || 'No invitations match this filter.'}
|
|
|
350
350
|
|
|
351
351
|
**Status meanings:** ⏳ PENDING - link sent, merchant has not acted. ✅ COMPLETED - merchant accepted;
|
|
352
352
|
obtain a token with \`payware_authorization_oauth2_obtain_token\`. ⌛ EXPIRED - the link lapsed; create
|
|
353
|
-
a new invitation. 🚫 CANCELLED - withdrawn by you
|
|
353
|
+
a new invitation. 🚫 CANCELLED - withdrawn by you, or by payware because the merchant it was addressed
|
|
354
|
+
to was deleted.
|
|
354
355
|
|
|
355
356
|
**Request ID:** ${result.requestId || 'N/A'}
|
|
356
357
|
**Timestamp:** ${result.timestamp}`
|
|
@@ -70,7 +70,7 @@ export const createProductTool = {
|
|
|
70
70
|
},
|
|
71
71
|
shop: {
|
|
72
72
|
type: "string",
|
|
73
|
-
description: "Shop code
|
|
73
|
+
description: "Shop code. If omitted, the merchant's default shop is used - which may be outside your assigned scope (403 ERR_SHOP_NOT_IN_SCOPE). Find valid codes with payware_shops_list.",
|
|
74
74
|
maxLength: 10
|
|
75
75
|
},
|
|
76
76
|
// Product Data Properties
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { createJWTToken
|
|
2
|
+
import { createJWTToken } from '../../core/auth/jwt-token.js';
|
|
3
3
|
import { createMinimizedJSON } from '../../core/utils/json-serializer.js';
|
|
4
4
|
import { getSandboxUrl, getProductionUrl, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
5
5
|
|