@vitemcp/server 1.10.1 → 1.10.3
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-STkC4R2N.d.cts → OAuthProvider-DN--f3j1.d.cts} +35 -4
- package/dist/{OAuthProvider-STkC4R2N.d.ts → OAuthProvider-DN--f3j1.d.ts} +35 -4
- package/dist/ViteMCP.cjs +4 -4
- package/dist/ViteMCP.d.cts +2 -2
- package/dist/ViteMCP.d.ts +2 -2
- package/dist/ViteMCP.js +3 -3
- 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-3W6VP3KX.js → chunk-EJVIGLUY.js} +3 -3
- package/dist/{chunk-4LU4AXU4.cjs → chunk-IWNTAHGZ.cjs} +70 -17
- package/dist/chunk-IWNTAHGZ.cjs.map +1 -0
- package/dist/{chunk-NLBRDP5F.js → chunk-KRS3VHYI.js} +62 -9
- package/dist/chunk-KRS3VHYI.js.map +1 -0
- package/dist/{chunk-FSPSPB7Y.cjs → chunk-PH2BAR5I.cjs} +9 -9
- package/dist/{chunk-FSPSPB7Y.cjs.map → chunk-PH2BAR5I.cjs.map} +1 -1
- package/dist/{chunk-NZGRSB2D.cjs → chunk-R4RK2DR2.cjs} +147 -3
- package/dist/chunk-R4RK2DR2.cjs.map +1 -0
- package/dist/{chunk-BLXUZUZ4.js → chunk-YDEROYNS.js} +147 -3
- package/dist/chunk-YDEROYNS.js.map +1 -0
- package/dist/edge/index.cjs +6 -6
- package/dist/edge/index.js +1 -1
- package/dist/openapi/index.cjs +27 -19
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +3 -3
- package/dist/openapi/index.d.ts +3 -3
- package/dist/openapi/index.js +17 -9
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-4LU4AXU4.cjs.map +0 -1
- package/dist/chunk-BLXUZUZ4.js.map +0 -1
- package/dist/chunk-NLBRDP5F.js.map +0 -1
- package/dist/chunk-NZGRSB2D.cjs.map +0 -1
- /package/dist/{chunk-3W6VP3KX.js.map → chunk-EJVIGLUY.js.map} +0 -0
|
@@ -594,6 +594,17 @@ var ClaimsExtractor = class {
|
|
|
594
594
|
maxClaimValueSize: config.maxClaimValueSize || 2e3
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* The claims of a token this proxy issued that came from upstream: all but
|
|
599
|
+
* its own, which are the ones never copied from upstream. `null` when there
|
|
600
|
+
* are none — an opaque upstream token, or passthrough found nothing.
|
|
601
|
+
*/
|
|
602
|
+
customClaimsOf(tokenClaims) {
|
|
603
|
+
const custom = Object.entries(tokenClaims).filter(
|
|
604
|
+
([key]) => !this.PROTECTED_CLAIMS.has(key)
|
|
605
|
+
);
|
|
606
|
+
return custom.length > 0 ? Object.fromEntries(custom) : null;
|
|
607
|
+
}
|
|
597
608
|
/**
|
|
598
609
|
* Extract claims from a token (access token or ID token)
|
|
599
610
|
*/
|
|
@@ -1939,9 +1950,15 @@ var OAuthProxy = class {
|
|
|
1939
1950
|
return this.redirectToUpstream(approvedTransaction);
|
|
1940
1951
|
}
|
|
1941
1952
|
/**
|
|
1942
|
-
*
|
|
1953
|
+
* What a ViteMCP access token stands for: the upstream tokens it maps to,
|
|
1954
|
+
* and the custom claims it carries (see `customClaimsPassthrough`). `null`
|
|
1955
|
+
* for any token `loadUpstreamTokens` refuses.
|
|
1956
|
+
*
|
|
1957
|
+
* One verification and one lookup give both. `authenticate` runs on every
|
|
1958
|
+
* request, so loading the claims separately would verify the token and read
|
|
1959
|
+
* its mapping again each time.
|
|
1943
1960
|
*/
|
|
1944
|
-
async
|
|
1961
|
+
async loadAccessToken(vitemcpToken) {
|
|
1945
1962
|
if (!this.jwtIssuer) {
|
|
1946
1963
|
return null;
|
|
1947
1964
|
}
|
|
@@ -1961,7 +1978,17 @@ var OAuthProxy = class {
|
|
|
1961
1978
|
const upstreamTokens = await this.tokenStorage.get(
|
|
1962
1979
|
`upstream:${this.issuerNs}:${mapping.upstreamTokenKey}`
|
|
1963
1980
|
);
|
|
1964
|
-
|
|
1981
|
+
if (!upstreamTokens) {
|
|
1982
|
+
return null;
|
|
1983
|
+
}
|
|
1984
|
+
const claims = this.claimsExtractor?.customClaimsOf(result.claims);
|
|
1985
|
+
return { ...claims ? { claims } : {}, upstreamTokens };
|
|
1986
|
+
}
|
|
1987
|
+
/**
|
|
1988
|
+
* Load upstream tokens from a ViteMCP JWT
|
|
1989
|
+
*/
|
|
1990
|
+
async loadUpstreamTokens(vitemcpToken) {
|
|
1991
|
+
return (await this.loadAccessToken(vitemcpToken))?.upstreamTokens ?? null;
|
|
1965
1992
|
}
|
|
1966
1993
|
/**
|
|
1967
1994
|
* RFC 7591 Dynamic Client Registration
|
|
@@ -2212,6 +2239,7 @@ var OAuthProxy = class {
|
|
|
2212
2239
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2213
2240
|
}
|
|
2214
2241
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2242
|
+
await this.verifyUpstreamAccessToken(tokens.access_token, "access_denied");
|
|
2215
2243
|
return {
|
|
2216
2244
|
accessToken: tokens.access_token,
|
|
2217
2245
|
// 0 when the upstream did not say, so `accessTokenTtl` and the defaults
|
|
@@ -2416,6 +2444,7 @@ var OAuthProxy = class {
|
|
|
2416
2444
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2417
2445
|
}
|
|
2418
2446
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2447
|
+
await this.verifyUpstreamAccessToken(tokens.access_token, "invalid_grant");
|
|
2419
2448
|
await this.savePassthroughRefreshBinding(
|
|
2420
2449
|
tokens.refresh_token || request2.refresh_token,
|
|
2421
2450
|
{
|
|
@@ -2936,6 +2965,7 @@ var OAuthProxy = class {
|
|
|
2936
2965
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2937
2966
|
}
|
|
2938
2967
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2968
|
+
await this.verifyUpstreamAccessToken(tokens.access_token, "invalid_grant");
|
|
2939
2969
|
return {
|
|
2940
2970
|
accessToken: tokens.access_token,
|
|
2941
2971
|
// 0 when the upstream did not say, as on the code exchange.
|
|
@@ -3138,6 +3168,25 @@ var OAuthProxy = class {
|
|
|
3138
3168
|
(pattern) => this.matchesPattern(url, pattern)
|
|
3139
3169
|
);
|
|
3140
3170
|
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Runs the configured `tokenVerifier` over an access token the upstream has
|
|
3173
|
+
* just issued, before it is stored or reaches a client. Accepted and never
|
|
3174
|
+
* called, the option let through every token a server had set it to refuse.
|
|
3175
|
+
*
|
|
3176
|
+
* RFC 6749 names the refusal differently at each endpoint: `access_denied`
|
|
3177
|
+
* for an authorization response (§4.1.2.1), `invalid_grant` for a token
|
|
3178
|
+
* response (§5.2). The verifier's own reason is not passed on: it describes
|
|
3179
|
+
* the token.
|
|
3180
|
+
*/
|
|
3181
|
+
async verifyUpstreamAccessToken(accessToken, errorCode) {
|
|
3182
|
+
const result = await this.config.tokenVerifier?.verify(accessToken);
|
|
3183
|
+
if (result && !result.valid) {
|
|
3184
|
+
throw new OAuthProxyError(
|
|
3185
|
+
errorCode,
|
|
3186
|
+
"Upstream access token failed verification"
|
|
3187
|
+
);
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3141
3190
|
};
|
|
3142
3191
|
var globComponent = (glob) => {
|
|
3143
3192
|
const source = glob.replace(/[.*+?^${}()|[\]\\]/g, (character) => {
|
|
@@ -3275,11 +3324,11 @@ var AuthProvider = class {
|
|
|
3275
3324
|
if (!token) {
|
|
3276
3325
|
return void 0;
|
|
3277
3326
|
}
|
|
3278
|
-
const
|
|
3279
|
-
if (!
|
|
3327
|
+
const loaded = await this.proxy.loadAccessToken(token);
|
|
3328
|
+
if (!loaded) {
|
|
3280
3329
|
return void 0;
|
|
3281
3330
|
}
|
|
3282
|
-
return this.createSession(upstreamTokens);
|
|
3331
|
+
return this.createSession(loaded.upstreamTokens, loaded.claims);
|
|
3283
3332
|
}
|
|
3284
3333
|
/**
|
|
3285
3334
|
* Release the resources held by the proxy this provider built for itself.
|
|
@@ -3325,13 +3374,17 @@ var AuthProvider = class {
|
|
|
3325
3374
|
return this.proxy;
|
|
3326
3375
|
}
|
|
3327
3376
|
/**
|
|
3328
|
-
* Create a session object from upstream tokens
|
|
3377
|
+
* Create a session object from upstream tokens, and the custom claims the
|
|
3378
|
+
* caller's token carries.
|
|
3329
3379
|
* Override in subclasses to add provider-specific session data.
|
|
3330
3380
|
*/
|
|
3331
|
-
createSession(upstreamTokens) {
|
|
3381
|
+
createSession(upstreamTokens, claims) {
|
|
3332
3382
|
const issuedAt = new Date(upstreamTokens.issuedAt).getTime() || Date.now();
|
|
3333
3383
|
return {
|
|
3334
3384
|
accessToken: upstreamTokens.accessToken,
|
|
3385
|
+
// Typed and documented, and never set: a `canAccess` reading a role
|
|
3386
|
+
// from it, as the guide's own example does, refused everyone.
|
|
3387
|
+
...claims ? { claims } : {},
|
|
3335
3388
|
expiresAt: upstreamTokens.expiresIn ? Math.floor(issuedAt / 1e3) + upstreamTokens.expiresIn : void 0,
|
|
3336
3389
|
idToken: upstreamTokens.idToken,
|
|
3337
3390
|
refreshToken: upstreamTokens.refreshToken,
|
|
@@ -3919,4 +3972,4 @@ export {
|
|
|
3919
3972
|
DiskStore,
|
|
3920
3973
|
JWKSVerifier
|
|
3921
3974
|
};
|
|
3922
|
-
//# sourceMappingURL=chunk-
|
|
3975
|
+
//# sourceMappingURL=chunk-KRS3VHYI.js.map
|