@vitemcp/server 1.10.2 → 1.10.4
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-DbC_47_h.d.cts} +38 -5
- package/dist/{OAuthProvider-STkC4R2N.d.ts → OAuthProvider-DbC_47_h.d.ts} +38 -5
- 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-NLBRDP5F.js → chunk-3QRGEISD.js} +113 -42
- package/dist/chunk-3QRGEISD.js.map +1 -0
- package/dist/{chunk-FSPSPB7Y.cjs → chunk-K2UCX3GS.cjs} +9 -9
- package/dist/{chunk-FSPSPB7Y.cjs.map → chunk-K2UCX3GS.cjs.map} +1 -1
- package/dist/{chunk-4LU4AXU4.cjs → chunk-LVPE26OW.cjs} +121 -50
- package/dist/chunk-LVPE26OW.cjs.map +1 -0
- package/dist/{chunk-3W6VP3KX.js → chunk-QYNWHXTM.js} +3 -3
- 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 +23 -16
- 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 +13 -6
- 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-QYNWHXTM.js.map} +0 -0
|
@@ -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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await 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
|
|
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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await 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");
|
|
@@ -383,6 +383,17 @@ var clientCodeStorageSchema = _zod.z.object({
|
|
|
383
383
|
upstreamTokens: upstreamTokenSetStorageSchema,
|
|
384
384
|
used: _zod.z.boolean().optional()
|
|
385
385
|
});
|
|
386
|
+
var upstreamCodeStorageSchema = _zod.z.object({
|
|
387
|
+
code: _zod.z.string().min(1),
|
|
388
|
+
scope: _zod.z.array(_zod.z.string())
|
|
389
|
+
});
|
|
390
|
+
var storedClientCodeSchema = _zod.z.union([
|
|
391
|
+
clientCodeStorageSchema,
|
|
392
|
+
clientCodeStorageSchema.omit({ upstreamTokens: true }).extend({
|
|
393
|
+
codeChallenge: _zod.z.string().min(1),
|
|
394
|
+
upstreamCode: upstreamCodeStorageSchema
|
|
395
|
+
}).refine(({ codeChallengeMethod }) => codeChallengeMethod === "S256")
|
|
396
|
+
]);
|
|
386
397
|
var spentClientCodeStorageSchema = _zod.z.object({
|
|
387
398
|
expiresAt: storedDateSchema,
|
|
388
399
|
used: _zod.z.literal(true)
|
|
@@ -396,6 +407,7 @@ var oauthTransactionStorageSchema = _zod.z.object({
|
|
|
396
407
|
consentGiven: _zod.z.boolean().optional(),
|
|
397
408
|
createdAt: storedDateSchema,
|
|
398
409
|
expiresAt: storedDateSchema,
|
|
410
|
+
forwardPkce: _zod.z.literal(true).optional(),
|
|
399
411
|
id: _zod.z.string(),
|
|
400
412
|
metadata: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional(),
|
|
401
413
|
proxyCodeChallenge: _zod.z.string(),
|
|
@@ -433,7 +445,7 @@ var OAuthProxyStateStore = class {
|
|
|
433
445
|
if (spent.success) {
|
|
434
446
|
return this.isExpired(spent.data.expiresAt) ? null : { expiresAt: spent.data.expiresAt, status: "spent" };
|
|
435
447
|
}
|
|
436
|
-
const parsed =
|
|
448
|
+
const parsed = storedClientCodeSchema.safeParse(stored);
|
|
437
449
|
if (!parsed.success || this.isExpired(parsed.data.expiresAt)) {
|
|
438
450
|
return null;
|
|
439
451
|
}
|
|
@@ -594,6 +606,17 @@ var ClaimsExtractor = (_class = class {
|
|
|
594
606
|
maxClaimValueSize: config.maxClaimValueSize || 2e3
|
|
595
607
|
};
|
|
596
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* The claims of a token this proxy issued that came from upstream: all but
|
|
611
|
+
* its own, which are the ones never copied from upstream. `null` when there
|
|
612
|
+
* are none — an opaque upstream token, or passthrough found nothing.
|
|
613
|
+
*/
|
|
614
|
+
customClaimsOf(tokenClaims) {
|
|
615
|
+
const custom = Object.entries(tokenClaims).filter(
|
|
616
|
+
([key]) => !this.PROTECTED_CLAIMS.has(key)
|
|
617
|
+
);
|
|
618
|
+
return custom.length > 0 ? Object.fromEntries(custom) : null;
|
|
619
|
+
}
|
|
597
620
|
/**
|
|
598
621
|
* Extract claims from a token (access token or ID token)
|
|
599
622
|
*/
|
|
@@ -1733,52 +1756,57 @@ var OAuthProxy = (_class4 = class {
|
|
|
1733
1756
|
`S256 PKCE is required for ${describeUnauthenticatedClient(client)}`
|
|
1734
1757
|
);
|
|
1735
1758
|
}
|
|
1759
|
+
const codeVerifier = request2.code_verifier;
|
|
1736
1760
|
if (clientCode.codeChallenge) {
|
|
1737
|
-
if (!
|
|
1761
|
+
if (!codeVerifier) {
|
|
1738
1762
|
throw new OAuthProxyError(
|
|
1739
1763
|
"invalid_request",
|
|
1740
1764
|
"code_verifier required for PKCE"
|
|
1741
1765
|
);
|
|
1742
1766
|
}
|
|
1743
1767
|
const valid = PKCEUtils.validateChallenge(
|
|
1744
|
-
|
|
1768
|
+
codeVerifier,
|
|
1745
1769
|
clientCode.codeChallenge,
|
|
1746
1770
|
clientCode.codeChallengeMethod
|
|
1747
1771
|
);
|
|
1748
1772
|
if (!valid) {
|
|
1749
1773
|
throw new OAuthProxyError("invalid_grant", "Invalid PKCE verifier");
|
|
1750
1774
|
}
|
|
1751
|
-
} else if (
|
|
1775
|
+
} else if (codeVerifier) {
|
|
1752
1776
|
throw new OAuthProxyError(
|
|
1753
1777
|
"invalid_request",
|
|
1754
1778
|
"code_verifier provided without a code_challenge"
|
|
1755
1779
|
);
|
|
1756
1780
|
}
|
|
1781
|
+
const upstreamTokens = "upstreamTokens" in clientCode ? clientCode.upstreamTokens : await this.exchangeUpstreamCode(clientCode.upstreamCode.code, {
|
|
1782
|
+
clientCodeVerifier: codeVerifier,
|
|
1783
|
+
scope: clientCode.upstreamCode.scope
|
|
1784
|
+
});
|
|
1757
1785
|
if (this.config.enableTokenSwap && this.jwtIssuer) {
|
|
1758
1786
|
return await this.issueSwappedTokens(
|
|
1759
1787
|
clientCode.clientId,
|
|
1760
|
-
|
|
1788
|
+
upstreamTokens,
|
|
1761
1789
|
authenticated
|
|
1762
1790
|
);
|
|
1763
1791
|
} else {
|
|
1764
1792
|
const response = {
|
|
1765
|
-
access_token:
|
|
1766
|
-
expires_in:
|
|
1767
|
-
token_type:
|
|
1793
|
+
access_token: upstreamTokens.accessToken,
|
|
1794
|
+
expires_in: upstreamTokens.expiresIn || 3600,
|
|
1795
|
+
token_type: upstreamTokens.tokenType
|
|
1768
1796
|
};
|
|
1769
|
-
if (
|
|
1797
|
+
if (upstreamTokens.refreshToken) {
|
|
1770
1798
|
await this.savePassthroughRefreshBinding(
|
|
1771
|
-
|
|
1799
|
+
upstreamTokens.refreshToken,
|
|
1772
1800
|
{ clientAuthenticated: authenticated, clientId: client.clientId },
|
|
1773
|
-
|
|
1801
|
+
upstreamTokens.refreshExpiresIn
|
|
1774
1802
|
);
|
|
1775
|
-
response.refresh_token =
|
|
1803
|
+
response.refresh_token = upstreamTokens.refreshToken;
|
|
1776
1804
|
}
|
|
1777
|
-
if (
|
|
1778
|
-
response.id_token =
|
|
1805
|
+
if (upstreamTokens.idToken) {
|
|
1806
|
+
response.id_token = upstreamTokens.idToken;
|
|
1779
1807
|
}
|
|
1780
|
-
if (
|
|
1781
|
-
response.scope =
|
|
1808
|
+
if (upstreamTokens.scope.length > 0) {
|
|
1809
|
+
response.scope = upstreamTokens.scope.join(" ");
|
|
1782
1810
|
}
|
|
1783
1811
|
return response;
|
|
1784
1812
|
}
|
|
@@ -1882,10 +1910,9 @@ var OAuthProxy = (_class4 = class {
|
|
|
1882
1910
|
relayableError(error, description)
|
|
1883
1911
|
);
|
|
1884
1912
|
}
|
|
1885
|
-
const upstreamTokens = await this.exchangeUpstreamCode(code, transaction);
|
|
1886
1913
|
const clientCode = await this.generateAuthorizationCode(
|
|
1887
1914
|
transaction,
|
|
1888
|
-
|
|
1915
|
+
transaction.forwardPkce ? { code, scope: transaction.scope } : await this.exchangeUpstreamCode(code, transaction)
|
|
1889
1916
|
);
|
|
1890
1917
|
return this.redirectToClient(transaction, { code: clientCode });
|
|
1891
1918
|
}
|
|
@@ -1939,9 +1966,15 @@ var OAuthProxy = (_class4 = class {
|
|
|
1939
1966
|
return this.redirectToUpstream(approvedTransaction);
|
|
1940
1967
|
}
|
|
1941
1968
|
/**
|
|
1942
|
-
*
|
|
1969
|
+
* What a ViteMCP access token stands for: the upstream tokens it maps to,
|
|
1970
|
+
* and the custom claims it carries (see `customClaimsPassthrough`). `null`
|
|
1971
|
+
* for any token `loadUpstreamTokens` refuses.
|
|
1972
|
+
*
|
|
1973
|
+
* One verification and one lookup give both. `authenticate` runs on every
|
|
1974
|
+
* request, so loading the claims separately would verify the token and read
|
|
1975
|
+
* its mapping again each time.
|
|
1943
1976
|
*/
|
|
1944
|
-
async
|
|
1977
|
+
async loadAccessToken(vitemcpToken) {
|
|
1945
1978
|
if (!this.jwtIssuer) {
|
|
1946
1979
|
return null;
|
|
1947
1980
|
}
|
|
@@ -1961,7 +1994,17 @@ var OAuthProxy = (_class4 = class {
|
|
|
1961
1994
|
const upstreamTokens = await this.tokenStorage.get(
|
|
1962
1995
|
`upstream:${this.issuerNs}:${mapping.upstreamTokenKey}`
|
|
1963
1996
|
);
|
|
1964
|
-
|
|
1997
|
+
if (!upstreamTokens) {
|
|
1998
|
+
return null;
|
|
1999
|
+
}
|
|
2000
|
+
const claims = _optionalChain([this, 'access', _24 => _24.claimsExtractor, 'optionalAccess', _25 => _25.customClaimsOf, 'call', _26 => _26(result.claims)]);
|
|
2001
|
+
return { ...claims ? { claims } : {}, upstreamTokens };
|
|
2002
|
+
}
|
|
2003
|
+
/**
|
|
2004
|
+
* Load upstream tokens from a ViteMCP JWT
|
|
2005
|
+
*/
|
|
2006
|
+
async loadUpstreamTokens(vitemcpToken) {
|
|
2007
|
+
return await _asyncNullishCoalesce(await _asyncOptionalChain([(await this.loadAccessToken(vitemcpToken)), 'optionalAccess', async _27 => _27.upstreamTokens]), async () => ( null));
|
|
1965
2008
|
}
|
|
1966
2009
|
/**
|
|
1967
2010
|
* RFC 7591 Dynamic Client Registration
|
|
@@ -2167,6 +2210,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2167
2210
|
expiresAt: new Date(
|
|
2168
2211
|
Date.now() + (this.config.transactionTtl || 600) * 1e3
|
|
2169
2212
|
),
|
|
2213
|
+
...this.config.forwardPkce && params.code_challenge && params.code_challenge_method === "S256" && { forwardPkce: true },
|
|
2170
2214
|
id: transactionId,
|
|
2171
2215
|
proxyCodeChallenge: proxyPkce.challenge,
|
|
2172
2216
|
proxyCodeVerifier: proxyPkce.verifier,
|
|
@@ -2180,11 +2224,12 @@ var OAuthProxy = (_class4 = class {
|
|
|
2180
2224
|
/**
|
|
2181
2225
|
* Exchange authorization code with upstream provider
|
|
2182
2226
|
*/
|
|
2183
|
-
async exchangeUpstreamCode(code,
|
|
2227
|
+
async exchangeUpstreamCode(code, exchange) {
|
|
2228
|
+
const forwardsPkce = "clientCodeVerifier" in exchange;
|
|
2184
2229
|
const useBasicAuth = this.config.upstreamTokenEndpointAuthMethod === "client_secret_basic";
|
|
2185
2230
|
const bodyParams = {
|
|
2186
2231
|
code,
|
|
2187
|
-
code_verifier:
|
|
2232
|
+
code_verifier: forwardsPkce ? exchange.clientCodeVerifier : exchange.proxyCodeVerifier,
|
|
2188
2233
|
grant_type: "authorization_code",
|
|
2189
2234
|
redirect_uri: `${this.config.baseUrl}${this.getRedirectPath()}`
|
|
2190
2235
|
};
|
|
@@ -2212,6 +2257,10 @@ var OAuthProxy = (_class4 = class {
|
|
|
2212
2257
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2213
2258
|
}
|
|
2214
2259
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2260
|
+
await this.verifyUpstreamAccessToken(
|
|
2261
|
+
tokens.access_token,
|
|
2262
|
+
forwardsPkce ? "invalid_grant" : "access_denied"
|
|
2263
|
+
);
|
|
2215
2264
|
return {
|
|
2216
2265
|
accessToken: tokens.access_token,
|
|
2217
2266
|
// 0 when the upstream did not say, so `accessTokenTtl` and the defaults
|
|
@@ -2222,7 +2271,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2222
2271
|
issuedAt: /* @__PURE__ */ new Date(),
|
|
2223
2272
|
refreshExpiresIn: tokens.refresh_expires_in,
|
|
2224
2273
|
refreshToken: tokens.refresh_token,
|
|
2225
|
-
scope: tokens.scope ? tokens.scope.split(" ") :
|
|
2274
|
+
scope: tokens.scope ? tokens.scope.split(" ") : exchange.scope,
|
|
2226
2275
|
tokenType: tokens.token_type || "Bearer"
|
|
2227
2276
|
};
|
|
2228
2277
|
}
|
|
@@ -2234,7 +2283,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2234
2283
|
throw new Error("JWT issuer not initialized");
|
|
2235
2284
|
}
|
|
2236
2285
|
const result = await this.jwtIssuer.verify(token);
|
|
2237
|
-
if (!result.valid || !_optionalChain([result, 'access',
|
|
2286
|
+
if (!result.valid || !_optionalChain([result, 'access', _28 => _28.claims, 'optionalAccess', _29 => _29.jti])) {
|
|
2238
2287
|
throw new Error("Failed to extract JTI from token");
|
|
2239
2288
|
}
|
|
2240
2289
|
return result.claims.jti;
|
|
@@ -2298,9 +2347,9 @@ var OAuthProxy = (_class4 = class {
|
|
|
2298
2347
|
/**
|
|
2299
2348
|
* Generate authorization code for client
|
|
2300
2349
|
*/
|
|
2301
|
-
async generateAuthorizationCode(transaction,
|
|
2350
|
+
async generateAuthorizationCode(transaction, upstream) {
|
|
2302
2351
|
const code = this.generateId();
|
|
2303
|
-
|
|
2352
|
+
await this.stateStore.saveClientCode({
|
|
2304
2353
|
clientId: transaction.clientId,
|
|
2305
2354
|
code,
|
|
2306
2355
|
codeChallenge: transaction.clientCodeChallenge,
|
|
@@ -2311,9 +2360,8 @@ var OAuthProxy = (_class4 = class {
|
|
|
2311
2360
|
),
|
|
2312
2361
|
redirectUri: transaction.clientCallbackUrl,
|
|
2313
2362
|
transactionId: transaction.id,
|
|
2314
|
-
upstreamTokens
|
|
2315
|
-
};
|
|
2316
|
-
await this.stateStore.saveClientCode(clientCode);
|
|
2363
|
+
..."accessToken" in upstream ? { upstreamTokens: upstream } : { upstreamCode: upstream }
|
|
2364
|
+
});
|
|
2317
2365
|
return code;
|
|
2318
2366
|
}
|
|
2319
2367
|
/**
|
|
@@ -2416,6 +2464,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2416
2464
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2417
2465
|
}
|
|
2418
2466
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2467
|
+
await this.verifyUpstreamAccessToken(tokens.access_token, "invalid_grant");
|
|
2419
2468
|
await this.savePassthroughRefreshBinding(
|
|
2420
2469
|
tokens.refresh_token || request2.refresh_token,
|
|
2421
2470
|
{
|
|
@@ -2828,7 +2877,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2828
2877
|
try {
|
|
2829
2878
|
return JSON.parse(text);
|
|
2830
2879
|
} catch (cause) {
|
|
2831
|
-
const mediaType = _optionalChain([response, 'access',
|
|
2880
|
+
const mediaType = _optionalChain([response, 'access', _30 => _30.headers, 'access', _31 => _31.get, 'call', _32 => _32("content-type"), 'optionalAccess', _33 => _33.split, 'call', _34 => _34(";", 1), 'access', _35 => _35[0], 'optionalAccess', _36 => _36.trim, 'call', _37 => _37(), 'access', _38 => _38.toLowerCase, 'call', _39 => _39()]);
|
|
2832
2881
|
if (mediaType === "application/x-www-form-urlencoded") {
|
|
2833
2882
|
const params = new URLSearchParams(text);
|
|
2834
2883
|
const error = params.get("error");
|
|
@@ -2888,13 +2937,11 @@ var OAuthProxy = (_class4 = class {
|
|
|
2888
2937
|
if (transaction.scope.length > 0) {
|
|
2889
2938
|
authUrl.searchParams.set("scope", transaction.scope.join(" "));
|
|
2890
2939
|
}
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
authUrl.searchParams.set("code_challenge_method", "S256");
|
|
2897
|
-
}
|
|
2940
|
+
authUrl.searchParams.set(
|
|
2941
|
+
"code_challenge",
|
|
2942
|
+
transaction.forwardPkce ? transaction.clientCodeChallenge : transaction.proxyCodeChallenge
|
|
2943
|
+
);
|
|
2944
|
+
authUrl.searchParams.set("code_challenge_method", "S256");
|
|
2898
2945
|
return new Response(null, {
|
|
2899
2946
|
headers: {
|
|
2900
2947
|
Location: authUrl.toString()
|
|
@@ -2936,6 +2983,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2936
2983
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2937
2984
|
}
|
|
2938
2985
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2986
|
+
await this.verifyUpstreamAccessToken(tokens.access_token, "invalid_grant");
|
|
2939
2987
|
return {
|
|
2940
2988
|
accessToken: tokens.access_token,
|
|
2941
2989
|
// 0 when the upstream did not say, as on the code exchange.
|
|
@@ -3068,7 +3116,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
3068
3116
|
this.cleanupInterval = setInterval(() => {
|
|
3069
3117
|
this.cleanup();
|
|
3070
3118
|
}, 6e4);
|
|
3071
|
-
_optionalChain([this, 'access',
|
|
3119
|
+
_optionalChain([this, 'access', _40 => _40.cleanupInterval, 'access', _41 => _41.unref, 'optionalCall', _42 => _42()]);
|
|
3072
3120
|
}
|
|
3073
3121
|
/**
|
|
3074
3122
|
* PKCE challenge methods this proxy accepts, advertised in the authorization
|
|
@@ -3138,6 +3186,25 @@ var OAuthProxy = (_class4 = class {
|
|
|
3138
3186
|
(pattern) => this.matchesPattern(url, pattern)
|
|
3139
3187
|
);
|
|
3140
3188
|
}
|
|
3189
|
+
/**
|
|
3190
|
+
* Runs the configured `tokenVerifier` over an access token the upstream has
|
|
3191
|
+
* just issued, before it is stored or reaches a client. Accepted and never
|
|
3192
|
+
* called, the option let through every token a server had set it to refuse.
|
|
3193
|
+
*
|
|
3194
|
+
* RFC 6749 names the refusal differently at each endpoint: `access_denied`
|
|
3195
|
+
* for an authorization response (§4.1.2.1), `invalid_grant` for a token
|
|
3196
|
+
* response (§5.2). The verifier's own reason is not passed on: it describes
|
|
3197
|
+
* the token.
|
|
3198
|
+
*/
|
|
3199
|
+
async verifyUpstreamAccessToken(accessToken, errorCode) {
|
|
3200
|
+
const result = await _optionalChain([this, 'access', _43 => _43.config, 'access', _44 => _44.tokenVerifier, 'optionalAccess', _45 => _45.verify, 'call', _46 => _46(accessToken)]);
|
|
3201
|
+
if (result && !result.valid) {
|
|
3202
|
+
throw new OAuthProxyError(
|
|
3203
|
+
errorCode,
|
|
3204
|
+
"Upstream access token failed verification"
|
|
3205
|
+
);
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3141
3208
|
}, _class4);
|
|
3142
3209
|
var globComponent = (glob) => {
|
|
3143
3210
|
const source = glob.replace(/[.*+?^${}()|[\]\\]/g, (character) => {
|
|
@@ -3269,17 +3336,17 @@ var AuthProvider = (_class5 = class {
|
|
|
3269
3336
|
if (!request2) {
|
|
3270
3337
|
return void 0;
|
|
3271
3338
|
}
|
|
3272
|
-
const token = _optionalChain([/^bearer +(\S.*)$/i, 'access',
|
|
3339
|
+
const token = _optionalChain([/^bearer +(\S.*)$/i, 'access', _47 => _47.exec, 'call', _48 => _48(
|
|
3273
3340
|
_nullishCoalesce(request2.headers.get("authorization"), () => ( ""))
|
|
3274
|
-
), 'optionalAccess',
|
|
3341
|
+
), 'optionalAccess', _49 => _49[1]]);
|
|
3275
3342
|
if (!token) {
|
|
3276
3343
|
return void 0;
|
|
3277
3344
|
}
|
|
3278
|
-
const
|
|
3279
|
-
if (!
|
|
3345
|
+
const loaded = await this.proxy.loadAccessToken(token);
|
|
3346
|
+
if (!loaded) {
|
|
3280
3347
|
return void 0;
|
|
3281
3348
|
}
|
|
3282
|
-
return this.createSession(upstreamTokens);
|
|
3349
|
+
return this.createSession(loaded.upstreamTokens, loaded.claims);
|
|
3283
3350
|
}
|
|
3284
3351
|
/**
|
|
3285
3352
|
* Release the resources held by the proxy this provider built for itself.
|
|
@@ -3300,7 +3367,7 @@ var AuthProvider = (_class5 = class {
|
|
|
3300
3367
|
*/
|
|
3301
3368
|
destroy() {
|
|
3302
3369
|
this._destroyed = true;
|
|
3303
|
-
_optionalChain([this, 'access',
|
|
3370
|
+
_optionalChain([this, 'access', _50 => _50._proxy, 'optionalAccess', _51 => _51.destroy, 'call', _52 => _52()]);
|
|
3304
3371
|
this._proxy = void 0;
|
|
3305
3372
|
}
|
|
3306
3373
|
/**
|
|
@@ -3325,13 +3392,17 @@ var AuthProvider = (_class5 = class {
|
|
|
3325
3392
|
return this.proxy;
|
|
3326
3393
|
}
|
|
3327
3394
|
/**
|
|
3328
|
-
* Create a session object from upstream tokens
|
|
3395
|
+
* Create a session object from upstream tokens, and the custom claims the
|
|
3396
|
+
* caller's token carries.
|
|
3329
3397
|
* Override in subclasses to add provider-specific session data.
|
|
3330
3398
|
*/
|
|
3331
|
-
createSession(upstreamTokens) {
|
|
3399
|
+
createSession(upstreamTokens, claims) {
|
|
3332
3400
|
const issuedAt = new Date(upstreamTokens.issuedAt).getTime() || Date.now();
|
|
3333
3401
|
return {
|
|
3334
3402
|
accessToken: upstreamTokens.accessToken,
|
|
3403
|
+
// Typed and documented, and never set: a `canAccess` reading a role
|
|
3404
|
+
// from it, as the guide's own example does, refused everyone.
|
|
3405
|
+
...claims ? { claims } : {},
|
|
3335
3406
|
expiresAt: upstreamTokens.expiresIn ? Math.floor(issuedAt / 1e3) + upstreamTokens.expiresIn : void 0,
|
|
3336
3407
|
idToken: upstreamTokens.idToken,
|
|
3337
3408
|
refreshToken: upstreamTokens.refreshToken,
|
|
@@ -3516,7 +3587,7 @@ var DiskStore = (_class6 = class {
|
|
|
3516
3587
|
this.cleanupInterval = setInterval(() => {
|
|
3517
3588
|
void this.cleanup();
|
|
3518
3589
|
}, cleanupIntervalMs);
|
|
3519
|
-
_optionalChain([this, 'access',
|
|
3590
|
+
_optionalChain([this, 'access', _53 => _53.cleanupInterval, 'access', _54 => _54.unref, 'optionalCall', _55 => _55()]);
|
|
3520
3591
|
}
|
|
3521
3592
|
/**
|
|
3522
3593
|
* Clean up expired entries.
|
|
@@ -3919,4 +3990,4 @@ Original error: ${error.message}`
|
|
|
3919
3990
|
|
|
3920
3991
|
|
|
3921
3992
|
exports.withoutTrailingSlash = withoutTrailingSlash; 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;
|
|
3922
|
-
//# sourceMappingURL=chunk-
|
|
3993
|
+
//# sourceMappingURL=chunk-LVPE26OW.cjs.map
|