@vitemcp/server 1.1.0 → 1.3.0
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/dist/{OAuthProvider-CQ64Us1B.d.cts → OAuthProvider-CoIruClQ.d.cts} +61 -0
- package/dist/{OAuthProvider-CQ64Us1B.d.ts → OAuthProvider-CoIruClQ.d.ts} +61 -0
- package/dist/ViteMCP.cjs +23 -2
- package/dist/ViteMCP.cjs.map +1 -1
- package/dist/ViteMCP.d.cts +21 -2
- package/dist/ViteMCP.d.ts +21 -2
- package/dist/ViteMCP.js +22 -1
- package/dist/ViteMCP.js.map +1 -1
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/{chunk-F5UZHHHH.cjs → chunk-XC4BVJQZ.cjs} +97 -22
- package/dist/chunk-XC4BVJQZ.cjs.map +1 -0
- package/dist/{chunk-WYT772UD.js → chunk-XZBHP34C.js} +81 -6
- package/dist/chunk-XZBHP34C.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-F5UZHHHH.cjs.map +0 -1
- package/dist/chunk-WYT772UD.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;// src/auth/helpers.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7;// src/auth/helpers.ts
|
|
2
2
|
function getAuthSession(session) {
|
|
3
3
|
if (!session) {
|
|
4
4
|
throw new Error("Session is not authenticated");
|
|
@@ -1190,11 +1190,11 @@ var PKCEUtils = class _PKCEUtils {
|
|
|
1190
1190
|
return false;
|
|
1191
1191
|
}
|
|
1192
1192
|
if (method === "plain") {
|
|
1193
|
-
return verifier
|
|
1193
|
+
return equalsConstantTime(verifier, challenge);
|
|
1194
1194
|
}
|
|
1195
1195
|
if (method === "S256") {
|
|
1196
1196
|
const computedChallenge = _PKCEUtils.generateChallenge(verifier, "S256");
|
|
1197
|
-
return computedChallenge
|
|
1197
|
+
return equalsConstantTime(computedChallenge, challenge);
|
|
1198
1198
|
}
|
|
1199
1199
|
return false;
|
|
1200
1200
|
}
|
|
@@ -1207,6 +1207,11 @@ var PKCEUtils = class _PKCEUtils {
|
|
|
1207
1207
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
1208
1208
|
}
|
|
1209
1209
|
};
|
|
1210
|
+
function equalsConstantTime(a, b) {
|
|
1211
|
+
const bufA = Buffer.from(a, "utf8");
|
|
1212
|
+
const bufB = Buffer.from(b, "utf8");
|
|
1213
|
+
return bufA.length === bufB.length && _crypto.timingSafeEqual.call(void 0, bufA, bufB);
|
|
1214
|
+
}
|
|
1210
1215
|
|
|
1211
1216
|
// src/auth/utils/tokenStore.ts
|
|
1212
1217
|
|
|
@@ -1389,16 +1394,24 @@ var OAuthProxy = (_class4 = class {
|
|
|
1389
1394
|
|
|
1390
1395
|
|
|
1391
1396
|
|
|
1397
|
+
/**
|
|
1398
|
+
* The fallback storage this proxy created for itself, if any. It runs a
|
|
1399
|
+
* cleanup timer that keeps the event loop alive, so `destroy()` has to stop
|
|
1400
|
+
* it — and once the storage is wrapped for encryption it is reachable
|
|
1401
|
+
* through nothing else. A caller-supplied storage is deliberately not
|
|
1402
|
+
* recorded here: its lifetime belongs to the caller.
|
|
1403
|
+
*/
|
|
1404
|
+
__init7() {this.ownedTokenStorage = null}
|
|
1392
1405
|
/**
|
|
1393
1406
|
* Keyed by proxy-issued client_id for authorize/token-exchange lookups and
|
|
1394
1407
|
* for the defence-in-depth callback checks. A registration never changes
|
|
1395
1408
|
* after it is written, so caching it locally cannot go stale; it is also
|
|
1396
1409
|
* persisted, so another instance can hydrate it.
|
|
1397
1410
|
*/
|
|
1398
|
-
|
|
1411
|
+
__init8() {this.registeredClientsByClientId = /* @__PURE__ */ new Map()}
|
|
1399
1412
|
|
|
1400
1413
|
|
|
1401
|
-
constructor(config) {;_class4.prototype.__init5.call(this);_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);
|
|
1414
|
+
constructor(config) {;_class4.prototype.__init5.call(this);_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);
|
|
1402
1415
|
this.config = {
|
|
1403
1416
|
authorizationCodeTtl: DEFAULT_AUTHORIZATION_CODE_TTL,
|
|
1404
1417
|
consentRequired: true,
|
|
@@ -1410,7 +1423,11 @@ var OAuthProxy = (_class4 = class {
|
|
|
1410
1423
|
upstreamTokenEndpointAuthMethod: "client_secret_basic",
|
|
1411
1424
|
...config
|
|
1412
1425
|
};
|
|
1413
|
-
let storage = config.tokenStorage
|
|
1426
|
+
let storage = config.tokenStorage;
|
|
1427
|
+
if (!storage) {
|
|
1428
|
+
this.ownedTokenStorage = new MemoryTokenStorage();
|
|
1429
|
+
storage = this.ownedTokenStorage;
|
|
1430
|
+
}
|
|
1414
1431
|
const isAlreadyEncrypted = storage.constructor.name === "EncryptedTokenStorage";
|
|
1415
1432
|
if (!isAlreadyEncrypted && config.encryptionKey !== false) {
|
|
1416
1433
|
const encryptionKey = typeof config.encryptionKey === "string" ? config.encryptionKey : this.generateSigningKey();
|
|
@@ -1474,6 +1491,14 @@ var OAuthProxy = (_class4 = class {
|
|
|
1474
1491
|
"code_challenge_method required when code_challenge is present"
|
|
1475
1492
|
);
|
|
1476
1493
|
}
|
|
1494
|
+
if (params.code_challenge && params.code_challenge_method && !this.supportedCodeChallengeMethods().includes(
|
|
1495
|
+
params.code_challenge_method
|
|
1496
|
+
)) {
|
|
1497
|
+
throw new OAuthProxyError(
|
|
1498
|
+
"invalid_request",
|
|
1499
|
+
`Unsupported code_challenge_method: ${params.code_challenge_method}`
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1477
1502
|
const transaction = await this.createTransaction(params);
|
|
1478
1503
|
if (this.config.consentRequired && !transaction.consentGiven) {
|
|
1479
1504
|
return this.consentManager.createConsentResponse(
|
|
@@ -1491,6 +1516,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1491
1516
|
clearInterval(this.cleanupInterval);
|
|
1492
1517
|
this.cleanupInterval = null;
|
|
1493
1518
|
}
|
|
1519
|
+
_optionalChain([this, 'access', _10 => _10.ownedTokenStorage, 'optionalAccess', _11 => _11.destroy, 'call', _12 => _12()]);
|
|
1494
1520
|
this.registeredClientsByClientId.clear();
|
|
1495
1521
|
}
|
|
1496
1522
|
/**
|
|
@@ -1590,7 +1616,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1590
1616
|
authorizationResponseIssParameterSupported: true,
|
|
1591
1617
|
// Clients prefer CIMD over DCR when both are offered.
|
|
1592
1618
|
clientIdMetadataDocumentSupported: this.clientIdMetadata.enabled,
|
|
1593
|
-
codeChallengeMethodsSupported:
|
|
1619
|
+
codeChallengeMethodsSupported: this.supportedCodeChallengeMethods(),
|
|
1594
1620
|
grantTypesSupported: ["authorization_code", "refresh_token"],
|
|
1595
1621
|
issuer: this.config.baseUrl,
|
|
1596
1622
|
registrationEndpoint: `${this.config.baseUrl}/oauth/register`,
|
|
@@ -1715,7 +1741,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1715
1741
|
return null;
|
|
1716
1742
|
}
|
|
1717
1743
|
const result = await this.jwtIssuer.verify(vitemcpToken);
|
|
1718
|
-
if (!result.valid || !_optionalChain([result, 'access',
|
|
1744
|
+
if (!result.valid || !_optionalChain([result, 'access', _13 => _13.claims, 'optionalAccess', _14 => _14.jti])) {
|
|
1719
1745
|
return null;
|
|
1720
1746
|
}
|
|
1721
1747
|
const mapping = await this.tokenStorage.get(
|
|
@@ -1913,7 +1939,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1913
1939
|
throw new Error("JWT issuer not initialized");
|
|
1914
1940
|
}
|
|
1915
1941
|
const result = await this.jwtIssuer.verify(token);
|
|
1916
|
-
if (!result.valid || !_optionalChain([result, 'access',
|
|
1942
|
+
if (!result.valid || !_optionalChain([result, 'access', _15 => _15.claims, 'optionalAccess', _16 => _16.jti])) {
|
|
1917
1943
|
throw new Error("Failed to extract JTI from token");
|
|
1918
1944
|
}
|
|
1919
1945
|
return result.claims.jti;
|
|
@@ -2095,7 +2121,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2095
2121
|
"Invalid or expired refresh token"
|
|
2096
2122
|
);
|
|
2097
2123
|
}
|
|
2098
|
-
const jti = _optionalChain([verifyResult, 'access',
|
|
2124
|
+
const jti = _optionalChain([verifyResult, 'access', _17 => _17.claims, 'optionalAccess', _18 => _18.jti]);
|
|
2099
2125
|
if (!jti) {
|
|
2100
2126
|
throw new OAuthProxyError("invalid_grant", "Refresh token missing JTI");
|
|
2101
2127
|
}
|
|
@@ -2475,6 +2501,19 @@ var OAuthProxy = (_class4 = class {
|
|
|
2475
2501
|
this.cleanup();
|
|
2476
2502
|
}, 6e4);
|
|
2477
2503
|
}
|
|
2504
|
+
/**
|
|
2505
|
+
* PKCE challenge methods this proxy accepts, advertised in the authorization
|
|
2506
|
+
* server metadata and enforced at /oauth/authorize.
|
|
2507
|
+
*
|
|
2508
|
+
* S256 only by default. `plain` makes the challenge and the verifier the same
|
|
2509
|
+
* value, so the secret needed to redeem an authorization code is exposed
|
|
2510
|
+
* everywhere the authorization request is: browser history, referrer headers,
|
|
2511
|
+
* proxy logs. RFC 7636 §4.2 requires S256 of any client that can hash, and
|
|
2512
|
+
* OAuth 2.1 removes `plain` entirely.
|
|
2513
|
+
*/
|
|
2514
|
+
supportedCodeChallengeMethods() {
|
|
2515
|
+
return this.config.allowPlainPkce ? ["S256", "plain"] : ["S256"];
|
|
2516
|
+
}
|
|
2478
2517
|
/**
|
|
2479
2518
|
* Atomically claim a token mapping, mirroring `OAuthProxyStateStore`: at most
|
|
2480
2519
|
* one caller — across all processes sharing the storage — can receive a given
|
|
@@ -2561,19 +2600,33 @@ var OAuthProxyError = class extends Error {
|
|
|
2561
2600
|
};
|
|
2562
2601
|
|
|
2563
2602
|
// src/auth/providers/AuthProvider.ts
|
|
2564
|
-
var AuthProvider = class {
|
|
2603
|
+
var AuthProvider = (_class5 = class {
|
|
2565
2604
|
|
|
2566
2605
|
/**
|
|
2567
2606
|
* Get the proxy, creating it lazily if needed.
|
|
2607
|
+
*
|
|
2608
|
+
* Refuses to rebuild after `destroy()`. Lazily replacing a torn-down proxy
|
|
2609
|
+
* would be silently wrong twice over: the replacement starts the very timers
|
|
2610
|
+
* `destroy()` released, and `ViteMCP` captured the original by reference when
|
|
2611
|
+
* it mounted the OAuth routes, so the token endpoint would keep answering
|
|
2612
|
+
* from the old instance while `authenticate()` verified against the new one —
|
|
2613
|
+
* with different auto-generated signing keys, every token minted by one is
|
|
2614
|
+
* invalid to the other.
|
|
2568
2615
|
*/
|
|
2569
2616
|
get proxy() {
|
|
2617
|
+
if (this._destroyed) {
|
|
2618
|
+
throw new Error(
|
|
2619
|
+
"AuthProvider has been destroyed. Create a new provider rather than reusing this one."
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
2570
2622
|
if (!this._proxy) {
|
|
2571
2623
|
this._proxy = this.createProxy();
|
|
2572
2624
|
}
|
|
2573
2625
|
return this._proxy;
|
|
2574
2626
|
}
|
|
2627
|
+
__init9() {this._destroyed = false}
|
|
2575
2628
|
|
|
2576
|
-
constructor(config) {
|
|
2629
|
+
constructor(config) {;_class5.prototype.__init9.call(this);
|
|
2577
2630
|
this.config = config;
|
|
2578
2631
|
}
|
|
2579
2632
|
/**
|
|
@@ -2595,6 +2648,28 @@ var AuthProvider = class {
|
|
|
2595
2648
|
}
|
|
2596
2649
|
return this.createSession(upstreamTokens);
|
|
2597
2650
|
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Release the resources held by the proxy this provider built for itself.
|
|
2653
|
+
*
|
|
2654
|
+
* That proxy runs two cleanup timers — its own sweep and its token
|
|
2655
|
+
* storage's — and both keep the Node event loop alive, so a process that has
|
|
2656
|
+
* stopped serving does not exit until this runs. `getProxy().destroy()`
|
|
2657
|
+
* reaches the same teardown; this exists so a caller holding only the
|
|
2658
|
+
* provider does not have to know that.
|
|
2659
|
+
*
|
|
2660
|
+
* Terminal: the provider will not serve again afterwards, and any later use
|
|
2661
|
+
* throws rather than quietly building a replacement. Call it when the process
|
|
2662
|
+
* is shutting down, after the HTTP server has finished draining — a request
|
|
2663
|
+
* still in flight would otherwise resurrect what this just released.
|
|
2664
|
+
*
|
|
2665
|
+
* Safe to call more than once, and a no-op if the lazy proxy was never
|
|
2666
|
+
* created.
|
|
2667
|
+
*/
|
|
2668
|
+
destroy() {
|
|
2669
|
+
this._destroyed = true;
|
|
2670
|
+
_optionalChain([this, 'access', _19 => _19._proxy, 'optionalAccess', _20 => _20.destroy, 'call', _21 => _21()]);
|
|
2671
|
+
this._proxy = void 0;
|
|
2672
|
+
}
|
|
2598
2673
|
/**
|
|
2599
2674
|
* Get the OAuth configuration object for ViteMCP ServerOptions.
|
|
2600
2675
|
*/
|
|
@@ -2629,7 +2704,7 @@ var AuthProvider = class {
|
|
|
2629
2704
|
scopes: upstreamTokens.scope
|
|
2630
2705
|
};
|
|
2631
2706
|
}
|
|
2632
|
-
};
|
|
2707
|
+
}, _class5);
|
|
2633
2708
|
|
|
2634
2709
|
// src/auth/providers/AzureProvider.ts
|
|
2635
2710
|
var AzureProvider = class extends AuthProvider {
|
|
@@ -2784,11 +2859,11 @@ var OAuthProvider = class extends AuthProvider {
|
|
|
2784
2859
|
|
|
2785
2860
|
var _promises = require('fs/promises');
|
|
2786
2861
|
var _path = require('path');
|
|
2787
|
-
var DiskStore = (
|
|
2788
|
-
|
|
2862
|
+
var DiskStore = (_class6 = class {
|
|
2863
|
+
__init10() {this.cleanupInterval = null}
|
|
2789
2864
|
|
|
2790
2865
|
|
|
2791
|
-
constructor(options) {;
|
|
2866
|
+
constructor(options) {;_class6.prototype.__init10.call(this);
|
|
2792
2867
|
this.directory = options.directory;
|
|
2793
2868
|
this.fileExtension = options.fileExtension || ".json";
|
|
2794
2869
|
void this.ensureDirectory();
|
|
@@ -2955,15 +3030,15 @@ var DiskStore = (_class5 = class {
|
|
|
2955
3030
|
const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2956
3031
|
return _path.join.call(void 0, this.directory, `${sanitizedKey}${this.fileExtension}`);
|
|
2957
3032
|
}
|
|
2958
|
-
},
|
|
3033
|
+
}, _class6);
|
|
2959
3034
|
|
|
2960
3035
|
// src/auth/utils/jwks.ts
|
|
2961
|
-
var JWKSVerifier = (
|
|
3036
|
+
var JWKSVerifier = (_class7 = class {
|
|
2962
3037
|
|
|
2963
3038
|
|
|
2964
|
-
|
|
3039
|
+
__init11() {this.joseLoaded = false}
|
|
2965
3040
|
|
|
2966
|
-
constructor(config) {;
|
|
3041
|
+
constructor(config) {;_class7.prototype.__init11.call(this);
|
|
2967
3042
|
this.config = {
|
|
2968
3043
|
cacheDuration: 36e5,
|
|
2969
3044
|
// 1 hour
|
|
@@ -3092,7 +3167,7 @@ Original error: ${error.message}`
|
|
|
3092
3167
|
}
|
|
3093
3168
|
return [];
|
|
3094
3169
|
}
|
|
3095
|
-
},
|
|
3170
|
+
}, _class7);
|
|
3096
3171
|
|
|
3097
3172
|
|
|
3098
3173
|
|
|
@@ -3121,4 +3196,4 @@ Original error: ${error.message}`
|
|
|
3121
3196
|
|
|
3122
3197
|
|
|
3123
3198
|
exports.getAuthSession = getAuthSession; exports.requireAll = requireAll; exports.requireAny = requireAny; exports.requireAuth = requireAuth; exports.requireRole = requireRole; exports.requireScopes = requireScopes; exports.DEFAULT_ACCESS_TOKEN_TTL = DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_REFRESH_TOKEN_TTL = DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_AUTHORIZATION_CODE_TTL = DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_TRANSACTION_TTL = DEFAULT_TRANSACTION_TTL; exports.ConsentManager = ConsentManager; exports.JWTIssuer = JWTIssuer; exports.PKCEUtils = PKCEUtils; exports.EncryptedTokenStorage = EncryptedTokenStorage; exports.MemoryTokenStorage = MemoryTokenStorage; exports.OAuthProxy = OAuthProxy; exports.OAuthProxyError = OAuthProxyError; exports.AuthProvider = AuthProvider; exports.AzureProvider = AzureProvider; exports.GitHubProvider = GitHubProvider; exports.GoogleProvider = GoogleProvider; exports.OAuthProvider = OAuthProvider; exports.DiskStore = DiskStore; exports.JWKSVerifier = JWKSVerifier;
|
|
3124
|
-
//# sourceMappingURL=chunk-
|
|
3199
|
+
//# sourceMappingURL=chunk-XC4BVJQZ.cjs.map
|