@vitemcp/server 1.9.8 → 1.9.9
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-BaPwgWny.d.cts → OAuthProvider-Dt3F-oDh.d.cts} +54 -0
- package/dist/{OAuthProvider-BaPwgWny.d.ts → OAuthProvider-Dt3F-oDh.d.ts} +54 -0
- package/dist/ViteMCP.cjs +3 -3
- package/dist/ViteMCP.d.cts +2 -2
- package/dist/ViteMCP.d.ts +2 -2
- package/dist/ViteMCP.js +2 -2
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +10 -2
- package/dist/auth/index.d.ts +10 -2
- package/dist/auth/index.js +1 -1
- package/dist/{chunk-XU7XBDZI.cjs → chunk-2FAJF3V6.cjs} +62 -15
- package/dist/chunk-2FAJF3V6.cjs.map +1 -0
- package/dist/{chunk-NLFL6ISL.cjs → chunk-PNWCRGJY.cjs} +213 -47
- package/dist/chunk-PNWCRGJY.cjs.map +1 -0
- package/dist/{chunk-QZ6S3FM5.js → chunk-UVKIOOZA.js} +57 -10
- package/dist/{chunk-QZ6S3FM5.js.map → chunk-UVKIOOZA.js.map} +1 -1
- package/dist/{chunk-76HUSLES.js → chunk-ZVK5GKEO.js} +213 -47
- package/dist/chunk-ZVK5GKEO.js.map +1 -0
- package/dist/openapi/index.cjs +12 -12
- package/dist/openapi/index.d.cts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-76HUSLES.js.map +0 -1
- package/dist/chunk-NLFL6ISL.cjs.map +0 -1
- package/dist/chunk-XU7XBDZI.cjs.map +0 -1
|
@@ -34,7 +34,7 @@ function requireScopes(...requiredScopes) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// src/auth/OAuthProxy.ts
|
|
37
|
-
import { randomBytes as randomBytes4 } from "crypto";
|
|
37
|
+
import { createHash as createHash3, randomBytes as randomBytes4, timingSafeEqual as timingSafeEqual4 } from "crypto";
|
|
38
38
|
import { z as z2 } from "zod";
|
|
39
39
|
|
|
40
40
|
// src/auth/clientIdMetadata.ts
|
|
@@ -304,6 +304,21 @@ var ClientIdMetadataResolver = class {
|
|
|
304
304
|
// src/auth/OAuthProxyStateStore.ts
|
|
305
305
|
import { createHash } from "crypto";
|
|
306
306
|
import { z } from "zod";
|
|
307
|
+
|
|
308
|
+
// src/auth/types.ts
|
|
309
|
+
var DEFAULT_ACCESS_TOKEN_TTL = 3600;
|
|
310
|
+
var DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = 31536e3;
|
|
311
|
+
var DEFAULT_REFRESH_TOKEN_TTL = 2592e3;
|
|
312
|
+
var TOKEN_ENDPOINT_AUTH_METHODS = [
|
|
313
|
+
"client_secret_basic",
|
|
314
|
+
"client_secret_post",
|
|
315
|
+
"none"
|
|
316
|
+
];
|
|
317
|
+
var DEFAULT_AUTHORIZATION_CODE_TTL = 300;
|
|
318
|
+
var DEFAULT_TRANSACTION_TTL = 600;
|
|
319
|
+
var DEFAULT_UPSTREAM_REQUEST_TIMEOUT_MS = 1e4;
|
|
320
|
+
|
|
321
|
+
// src/auth/OAuthProxyStateStore.ts
|
|
307
322
|
var STORAGE_KEY_PREFIX = {
|
|
308
323
|
client: "client:",
|
|
309
324
|
code: "code:",
|
|
@@ -340,7 +355,11 @@ var proxyDcrClientStorageSchema = z.object({
|
|
|
340
355
|
clientSecret: z.string().optional(),
|
|
341
356
|
metadata: dcrClientMetadataSchema.optional(),
|
|
342
357
|
redirectUris: z.array(z.string()),
|
|
343
|
-
registeredAt: storedDateSchema
|
|
358
|
+
registeredAt: storedDateSchema,
|
|
359
|
+
// Optional: registrations written before it was recorded do not carry it.
|
|
360
|
+
// Listed so that it survives a read — an unlisted key is stripped, which
|
|
361
|
+
// would quietly turn every confidential client back into a legacy one.
|
|
362
|
+
tokenEndpointAuthMethod: z.enum(TOKEN_ENDPOINT_AUTH_METHODS).optional()
|
|
344
363
|
});
|
|
345
364
|
var upstreamTokenSetStorageSchema = z.object({
|
|
346
365
|
accessToken: z.string(),
|
|
@@ -539,14 +558,6 @@ var OAuthProxyStateStore = class {
|
|
|
539
558
|
}
|
|
540
559
|
};
|
|
541
560
|
|
|
542
|
-
// src/auth/types.ts
|
|
543
|
-
var DEFAULT_ACCESS_TOKEN_TTL = 3600;
|
|
544
|
-
var DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = 31536e3;
|
|
545
|
-
var DEFAULT_REFRESH_TOKEN_TTL = 2592e3;
|
|
546
|
-
var DEFAULT_AUTHORIZATION_CODE_TTL = 300;
|
|
547
|
-
var DEFAULT_TRANSACTION_TTL = 600;
|
|
548
|
-
var DEFAULT_UPSTREAM_REQUEST_TIMEOUT_MS = 1e4;
|
|
549
|
-
|
|
550
561
|
// src/auth/utils/claimsExtractor.ts
|
|
551
562
|
var ClaimsExtractor = class {
|
|
552
563
|
config;
|
|
@@ -560,7 +571,9 @@ var ClaimsExtractor = class {
|
|
|
560
571
|
"jti",
|
|
561
572
|
"nbf",
|
|
562
573
|
// The proxy's own grant decision — an upstream `scope` must never replace it.
|
|
563
|
-
"scope"
|
|
574
|
+
"scope",
|
|
575
|
+
// Whether a proxy token is an access or a refresh token.
|
|
576
|
+
"token_use"
|
|
564
577
|
]);
|
|
565
578
|
constructor(config) {
|
|
566
579
|
if (typeof config === "boolean") {
|
|
@@ -1044,7 +1057,8 @@ var JWTIssuer = class {
|
|
|
1044
1057
|
iat: now,
|
|
1045
1058
|
iss: this.issuer,
|
|
1046
1059
|
jti,
|
|
1047
|
-
scope
|
|
1060
|
+
scope,
|
|
1061
|
+
token_use: "access"
|
|
1048
1062
|
};
|
|
1049
1063
|
return this.signToken(claims);
|
|
1050
1064
|
}
|
|
@@ -1063,7 +1077,8 @@ var JWTIssuer = class {
|
|
|
1063
1077
|
iat: now,
|
|
1064
1078
|
iss: this.issuer,
|
|
1065
1079
|
jti,
|
|
1066
|
-
scope
|
|
1080
|
+
scope,
|
|
1081
|
+
token_use: "refresh"
|
|
1067
1082
|
};
|
|
1068
1083
|
return this.signToken(claims);
|
|
1069
1084
|
}
|
|
@@ -1449,6 +1464,10 @@ var RESERVED_AUTHORIZATION_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1449
1464
|
"scope",
|
|
1450
1465
|
"state"
|
|
1451
1466
|
]);
|
|
1467
|
+
var passthroughRefreshBindingSchema = z2.object({
|
|
1468
|
+
clientAuthenticated: z2.boolean(),
|
|
1469
|
+
clientId: z2.string()
|
|
1470
|
+
});
|
|
1452
1471
|
var OAuthProxy = class {
|
|
1453
1472
|
claimsExtractor = null;
|
|
1454
1473
|
cleanupInterval = null;
|
|
@@ -1564,17 +1583,18 @@ var OAuthProxy = class {
|
|
|
1564
1583
|
`Unsupported code_challenge_method: ${params.code_challenge_method}`
|
|
1565
1584
|
);
|
|
1566
1585
|
}
|
|
1567
|
-
if (registeredClient
|
|
1586
|
+
if (isPublicClient(registeredClient)) {
|
|
1587
|
+
const kind = describeUnauthenticatedClient(registeredClient);
|
|
1568
1588
|
if (!params.code_challenge) {
|
|
1569
1589
|
throw new OAuthProxyError(
|
|
1570
1590
|
"invalid_request",
|
|
1571
|
-
|
|
1591
|
+
`code_challenge is required for ${kind}`
|
|
1572
1592
|
);
|
|
1573
1593
|
}
|
|
1574
1594
|
if (params.code_challenge_method !== "S256") {
|
|
1575
1595
|
throw new OAuthProxyError(
|
|
1576
1596
|
"invalid_request",
|
|
1577
|
-
|
|
1597
|
+
`code_challenge_method must be S256 for ${kind}`
|
|
1578
1598
|
);
|
|
1579
1599
|
}
|
|
1580
1600
|
}
|
|
@@ -1608,7 +1628,7 @@ var OAuthProxy = class {
|
|
|
1608
1628
|
"Only authorization_code grant type is supported"
|
|
1609
1629
|
);
|
|
1610
1630
|
}
|
|
1611
|
-
const client = await this.
|
|
1631
|
+
const { authenticated, client } = await this.authenticateClient(request2);
|
|
1612
1632
|
const consumed = await this.stateStore.consumeClientCode(request2.code);
|
|
1613
1633
|
if (!consumed) {
|
|
1614
1634
|
throw new OAuthProxyError(
|
|
@@ -1624,13 +1644,16 @@ var OAuthProxy = class {
|
|
|
1624
1644
|
);
|
|
1625
1645
|
}
|
|
1626
1646
|
const clientCode = consumed.clientCode;
|
|
1627
|
-
if (clientCode.clientId !==
|
|
1628
|
-
throw new OAuthProxyError(
|
|
1647
|
+
if (clientCode.clientId !== client.clientId) {
|
|
1648
|
+
throw new OAuthProxyError(
|
|
1649
|
+
"invalid_grant",
|
|
1650
|
+
"Authorization code was issued to another client"
|
|
1651
|
+
);
|
|
1629
1652
|
}
|
|
1630
|
-
if (
|
|
1653
|
+
if (!authenticated && (!clientCode.codeChallenge || clientCode.codeChallengeMethod !== "S256")) {
|
|
1631
1654
|
throw new OAuthProxyError(
|
|
1632
1655
|
"invalid_grant",
|
|
1633
|
-
|
|
1656
|
+
`S256 PKCE is required for ${describeUnauthenticatedClient(client)}`
|
|
1634
1657
|
);
|
|
1635
1658
|
}
|
|
1636
1659
|
if (clientCode.codeChallenge) {
|
|
@@ -1652,7 +1675,8 @@ var OAuthProxy = class {
|
|
|
1652
1675
|
if (this.config.enableTokenSwap && this.jwtIssuer) {
|
|
1653
1676
|
return await this.issueSwappedTokens(
|
|
1654
1677
|
clientCode.clientId,
|
|
1655
|
-
clientCode.upstreamTokens
|
|
1678
|
+
clientCode.upstreamTokens,
|
|
1679
|
+
authenticated
|
|
1656
1680
|
);
|
|
1657
1681
|
} else {
|
|
1658
1682
|
const response = {
|
|
@@ -1661,6 +1685,11 @@ var OAuthProxy = class {
|
|
|
1661
1685
|
token_type: clientCode.upstreamTokens.tokenType
|
|
1662
1686
|
};
|
|
1663
1687
|
if (clientCode.upstreamTokens.refreshToken) {
|
|
1688
|
+
await this.savePassthroughRefreshBinding(
|
|
1689
|
+
clientCode.upstreamTokens.refreshToken,
|
|
1690
|
+
{ clientAuthenticated: authenticated, clientId: client.clientId },
|
|
1691
|
+
clientCode.upstreamTokens.refreshExpiresIn
|
|
1692
|
+
);
|
|
1664
1693
|
response.refresh_token = clientCode.upstreamTokens.refreshToken;
|
|
1665
1694
|
}
|
|
1666
1695
|
if (clientCode.upstreamTokens.idToken) {
|
|
@@ -1682,10 +1711,11 @@ var OAuthProxy = class {
|
|
|
1682
1711
|
"Only refresh_token grant type is supported"
|
|
1683
1712
|
);
|
|
1684
1713
|
}
|
|
1714
|
+
const caller = await this.authenticateClient(request2);
|
|
1685
1715
|
if (this.config.enableTokenSwap && this.jwtIssuer) {
|
|
1686
|
-
return await this.handleSwapModeRefresh(request2);
|
|
1716
|
+
return await this.handleSwapModeRefresh(request2, caller);
|
|
1687
1717
|
}
|
|
1688
|
-
return await this.handlePassthroughRefresh(request2);
|
|
1718
|
+
return await this.handlePassthroughRefresh(request2, caller);
|
|
1689
1719
|
}
|
|
1690
1720
|
/**
|
|
1691
1721
|
* Get OAuth discovery metadata
|
|
@@ -1705,16 +1735,12 @@ var OAuthProxy = class {
|
|
|
1705
1735
|
responseTypesSupported: ["code"],
|
|
1706
1736
|
scopesSupported: this.config.scopes || [],
|
|
1707
1737
|
tokenEndpoint: `${this.config.baseUrl}/oauth/token`,
|
|
1708
|
-
// RFC 8414 §2.
|
|
1709
|
-
// response to carry a secret,
|
|
1710
|
-
//
|
|
1711
|
-
//
|
|
1712
|
-
//
|
|
1713
|
-
tokenEndpointAuthMethodsSupported: [
|
|
1714
|
-
"client_secret_basic",
|
|
1715
|
-
"client_secret_post",
|
|
1716
|
-
...this.clientIdMetadata.enabled ? ["none"] : []
|
|
1717
|
-
]
|
|
1738
|
+
// RFC 8414 §2. "none" is a public client: a CIMD client, which has no
|
|
1739
|
+
// registration response to carry a secret, or a DCR client that asked
|
|
1740
|
+
// for no secret. Either authenticates the exchange with S256 PKCE alone.
|
|
1741
|
+
// A client that reads this list to pick an auth method finds nothing it
|
|
1742
|
+
// can use unless "none" is advertised alongside the confidential methods.
|
|
1743
|
+
tokenEndpointAuthMethodsSupported: [...TOKEN_ENDPOINT_AUTH_METHODS]
|
|
1718
1744
|
};
|
|
1719
1745
|
}
|
|
1720
1746
|
/**
|
|
@@ -1832,6 +1858,9 @@ var OAuthProxy = class {
|
|
|
1832
1858
|
if (!result.valid || !result.claims?.jti) {
|
|
1833
1859
|
return null;
|
|
1834
1860
|
}
|
|
1861
|
+
if (result.claims.token_use !== "access") {
|
|
1862
|
+
return null;
|
|
1863
|
+
}
|
|
1835
1864
|
const mapping = await this.tokenStorage.get(
|
|
1836
1865
|
`mapping:${this.issuerNs}:${result.claims.jti}`
|
|
1837
1866
|
);
|
|
@@ -1868,8 +1897,15 @@ var OAuthProxy = class {
|
|
|
1868
1897
|
'application_type must be "native" or "web"'
|
|
1869
1898
|
);
|
|
1870
1899
|
}
|
|
1900
|
+
const tokenEndpointAuthMethod = request2.token_endpoint_auth_method || "client_secret_basic";
|
|
1901
|
+
if (!isTokenEndpointAuthMethod(tokenEndpointAuthMethod)) {
|
|
1902
|
+
throw new OAuthProxyError(
|
|
1903
|
+
"invalid_client_metadata",
|
|
1904
|
+
`Unsupported token_endpoint_auth_method: ${tokenEndpointAuthMethod}. Supported: ${TOKEN_ENDPOINT_AUTH_METHODS.join(", ")}`
|
|
1905
|
+
);
|
|
1906
|
+
}
|
|
1871
1907
|
const proxyClientId = randomBytes4(16).toString("hex");
|
|
1872
|
-
const proxyClientSecret = randomBytes4(32).toString("base64url");
|
|
1908
|
+
const proxyClientSecret = tokenEndpointAuthMethod === "none" ? void 0 : randomBytes4(32).toString("base64url");
|
|
1873
1909
|
const client = {
|
|
1874
1910
|
callbackUrl: request2.redirect_uris[0],
|
|
1875
1911
|
clientId: proxyClientId,
|
|
@@ -1889,7 +1925,8 @@ var OAuthProxy = class {
|
|
|
1889
1925
|
tos_uri: request2.tos_uri
|
|
1890
1926
|
},
|
|
1891
1927
|
redirectUris: request2.redirect_uris,
|
|
1892
|
-
registeredAt: /* @__PURE__ */ new Date()
|
|
1928
|
+
registeredAt: /* @__PURE__ */ new Date(),
|
|
1929
|
+
tokenEndpointAuthMethod
|
|
1893
1930
|
};
|
|
1894
1931
|
await this.stateStore.saveRegisteredClient(client);
|
|
1895
1932
|
this.stateStore.cacheRegisteredClient(client);
|
|
@@ -1901,8 +1938,9 @@ var OAuthProxy = class {
|
|
|
1901
1938
|
// Echo back optional metadata
|
|
1902
1939
|
client_name: request2.client_name,
|
|
1903
1940
|
client_secret: proxyClientSecret,
|
|
1904
|
-
|
|
1905
|
-
|
|
1941
|
+
// RFC 7591 §3.2.1: required alongside a secret, and only then.
|
|
1942
|
+
client_secret_expires_at: proxyClientSecret ? 0 : void 0,
|
|
1943
|
+
// 0: never
|
|
1906
1944
|
client_uri: request2.client_uri,
|
|
1907
1945
|
contacts: request2.contacts,
|
|
1908
1946
|
grant_types: request2.grant_types || [
|
|
@@ -1918,11 +1956,46 @@ var OAuthProxy = class {
|
|
|
1918
1956
|
scope: request2.scope,
|
|
1919
1957
|
software_id: request2.software_id,
|
|
1920
1958
|
software_version: request2.software_version,
|
|
1921
|
-
token_endpoint_auth_method:
|
|
1959
|
+
token_endpoint_auth_method: tokenEndpointAuthMethod,
|
|
1922
1960
|
tos_uri: request2.tos_uri
|
|
1923
1961
|
};
|
|
1924
1962
|
return response;
|
|
1925
1963
|
}
|
|
1964
|
+
/**
|
|
1965
|
+
* RFC 6749 §2.3 / §3.2.1: identify the client behind a token request and,
|
|
1966
|
+
* when it presents a secret, authenticate it.
|
|
1967
|
+
*
|
|
1968
|
+
* A client registered with a secret method must present its secret. A
|
|
1969
|
+
* public client must not present one: it was issued none. A registration
|
|
1970
|
+
* that predates recorded auth methods may do either — it was issued a
|
|
1971
|
+
* secret whatever it asked for — and is treated as unauthenticated when it
|
|
1972
|
+
* leaves it out, which the grants then hold it to.
|
|
1973
|
+
*
|
|
1974
|
+
* Throws `invalid_client` on any failure. Nothing here touches grant state,
|
|
1975
|
+
* so a caller that fails cannot spend a code or refresh token.
|
|
1976
|
+
*/
|
|
1977
|
+
async authenticateClient(request2) {
|
|
1978
|
+
if (!request2.client_id) {
|
|
1979
|
+
throw new OAuthProxyError("invalid_client", "client_id is required");
|
|
1980
|
+
}
|
|
1981
|
+
const client = await this.resolveClient(request2.client_id);
|
|
1982
|
+
if (request2.client_secret) {
|
|
1983
|
+
if (!client.clientSecret || !secretsMatch(request2.client_secret, client.clientSecret)) {
|
|
1984
|
+
throw new OAuthProxyError(
|
|
1985
|
+
"invalid_client",
|
|
1986
|
+
"Client authentication failed"
|
|
1987
|
+
);
|
|
1988
|
+
}
|
|
1989
|
+
return { authenticated: true, client };
|
|
1990
|
+
}
|
|
1991
|
+
if (client.tokenEndpointAuthMethod === "client_secret_basic" || client.tokenEndpointAuthMethod === "client_secret_post") {
|
|
1992
|
+
throw new OAuthProxyError(
|
|
1993
|
+
"invalid_client",
|
|
1994
|
+
"Client authentication failed: client_secret is required"
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
return { authenticated: false, client };
|
|
1998
|
+
}
|
|
1926
1999
|
/**
|
|
1927
2000
|
* Calculate access token TTL from upstream tokens
|
|
1928
2001
|
*/
|
|
@@ -2155,7 +2228,29 @@ var OAuthProxy = class {
|
|
|
2155
2228
|
/**
|
|
2156
2229
|
* Handle passthrough mode refresh - forward refresh token directly to upstream
|
|
2157
2230
|
*/
|
|
2158
|
-
async handlePassthroughRefresh(request2) {
|
|
2231
|
+
async handlePassthroughRefresh(request2, caller) {
|
|
2232
|
+
const bindingKey = this.passthroughRefreshKey(request2.refresh_token);
|
|
2233
|
+
const binding = passthroughRefreshBindingSchema.safeParse(
|
|
2234
|
+
await this.tokenStorage.get(bindingKey)
|
|
2235
|
+
);
|
|
2236
|
+
if (!binding.success) {
|
|
2237
|
+
throw new OAuthProxyError(
|
|
2238
|
+
"invalid_grant",
|
|
2239
|
+
"Invalid or expired refresh token"
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
if (binding.data.clientId !== caller.client.clientId) {
|
|
2243
|
+
throw new OAuthProxyError(
|
|
2244
|
+
"invalid_grant",
|
|
2245
|
+
"Refresh token was issued to another client"
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
if (binding.data.clientAuthenticated && !caller.authenticated) {
|
|
2249
|
+
throw new OAuthProxyError(
|
|
2250
|
+
"invalid_client",
|
|
2251
|
+
"Client authentication failed: client_secret is required"
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2159
2254
|
const useBasicAuth = this.config.upstreamTokenEndpointAuthMethod === "client_secret_basic";
|
|
2160
2255
|
const bodyParams = {
|
|
2161
2256
|
grant_type: "refresh_token",
|
|
@@ -2186,6 +2281,17 @@ var OAuthProxy = class {
|
|
|
2186
2281
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
2187
2282
|
}
|
|
2188
2283
|
const tokens = await this.parseTokenResponse(tokenResponse);
|
|
2284
|
+
await this.savePassthroughRefreshBinding(
|
|
2285
|
+
tokens.refresh_token || request2.refresh_token,
|
|
2286
|
+
{
|
|
2287
|
+
clientAuthenticated: caller.authenticated,
|
|
2288
|
+
clientId: caller.client.clientId
|
|
2289
|
+
},
|
|
2290
|
+
tokens.refresh_expires_in
|
|
2291
|
+
);
|
|
2292
|
+
if (tokens.refresh_token && tokens.refresh_token !== request2.refresh_token) {
|
|
2293
|
+
await this.tokenStorage.delete(bindingKey);
|
|
2294
|
+
}
|
|
2189
2295
|
return {
|
|
2190
2296
|
access_token: tokens.access_token,
|
|
2191
2297
|
expires_in: tokens.expires_in || 3600,
|
|
@@ -2198,21 +2304,30 @@ var OAuthProxy = class {
|
|
|
2198
2304
|
/**
|
|
2199
2305
|
* Handle swap mode refresh - verify ViteMCP JWT and issue new tokens
|
|
2200
2306
|
*/
|
|
2201
|
-
async handleSwapModeRefresh(request2) {
|
|
2307
|
+
async handleSwapModeRefresh(request2, caller) {
|
|
2202
2308
|
if (!this.jwtIssuer) {
|
|
2203
2309
|
throw new Error("JWT issuer not initialized");
|
|
2204
2310
|
}
|
|
2205
2311
|
const verifyResult = await this.jwtIssuer.verify(request2.refresh_token);
|
|
2206
|
-
if (!verifyResult.valid) {
|
|
2312
|
+
if (!verifyResult.valid || !verifyResult.claims) {
|
|
2207
2313
|
throw new OAuthProxyError(
|
|
2208
2314
|
"invalid_grant",
|
|
2209
2315
|
"Invalid or expired refresh token"
|
|
2210
2316
|
);
|
|
2211
2317
|
}
|
|
2212
|
-
|
|
2318
|
+
if (verifyResult.claims.token_use !== "refresh") {
|
|
2319
|
+
throw new OAuthProxyError("invalid_grant", "Not a refresh token");
|
|
2320
|
+
}
|
|
2321
|
+
const jti = verifyResult.claims.jti;
|
|
2213
2322
|
if (!jti) {
|
|
2214
2323
|
throw new OAuthProxyError("invalid_grant", "Refresh token missing JTI");
|
|
2215
2324
|
}
|
|
2325
|
+
if (verifyResult.claims.client_id !== caller.client.clientId) {
|
|
2326
|
+
throw new OAuthProxyError(
|
|
2327
|
+
"invalid_grant",
|
|
2328
|
+
"Refresh token was issued to another client"
|
|
2329
|
+
);
|
|
2330
|
+
}
|
|
2216
2331
|
const mapping = await this.takeMapping(jti);
|
|
2217
2332
|
if (!mapping) {
|
|
2218
2333
|
throw new OAuthProxyError(
|
|
@@ -2221,6 +2336,18 @@ var OAuthProxy = class {
|
|
|
2221
2336
|
);
|
|
2222
2337
|
}
|
|
2223
2338
|
try {
|
|
2339
|
+
if (mapping.clientId !== caller.client.clientId) {
|
|
2340
|
+
throw new OAuthProxyError(
|
|
2341
|
+
"invalid_grant",
|
|
2342
|
+
"Refresh token was issued to another client"
|
|
2343
|
+
);
|
|
2344
|
+
}
|
|
2345
|
+
if (mapping.clientAuthenticated !== false && !caller.authenticated) {
|
|
2346
|
+
throw new OAuthProxyError(
|
|
2347
|
+
"invalid_client",
|
|
2348
|
+
"Client authentication failed: client_secret is required"
|
|
2349
|
+
);
|
|
2350
|
+
}
|
|
2224
2351
|
const upstreamTokens = await this.tokenStorage.get(
|
|
2225
2352
|
`upstream:${this.issuerNs}:${mapping.upstreamTokenKey}`
|
|
2226
2353
|
);
|
|
@@ -2256,7 +2383,8 @@ var OAuthProxy = class {
|
|
|
2256
2383
|
return await this.issueSwappedTokensForRefresh(
|
|
2257
2384
|
mapping.clientId,
|
|
2258
2385
|
refreshedUpstreamTokens,
|
|
2259
|
-
mapping.upstreamTokenKey
|
|
2386
|
+
mapping.upstreamTokenKey,
|
|
2387
|
+
caller.authenticated
|
|
2260
2388
|
);
|
|
2261
2389
|
} catch (error) {
|
|
2262
2390
|
try {
|
|
@@ -2274,7 +2402,7 @@ var OAuthProxy = class {
|
|
|
2274
2402
|
* Issue swapped tokens (JWT pattern)
|
|
2275
2403
|
* Issues short-lived ViteMCP JWTs and stores upstream tokens securely
|
|
2276
2404
|
*/
|
|
2277
|
-
async issueSwappedTokens(clientId, upstreamTokens) {
|
|
2405
|
+
async issueSwappedTokens(clientId, upstreamTokens, clientAuthenticated) {
|
|
2278
2406
|
if (!this.jwtIssuer) {
|
|
2279
2407
|
throw new Error("JWT issuer not initialized");
|
|
2280
2408
|
}
|
|
@@ -2333,6 +2461,7 @@ var OAuthProxy = class {
|
|
|
2333
2461
|
await this.tokenStorage.save(
|
|
2334
2462
|
`mapping:${this.issuerNs}:${refreshJti}`,
|
|
2335
2463
|
{
|
|
2464
|
+
clientAuthenticated,
|
|
2336
2465
|
clientId,
|
|
2337
2466
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2338
2467
|
expiresAt: new Date(Date.now() + refreshTokenTtl * 1e3),
|
|
@@ -2349,7 +2478,7 @@ var OAuthProxy = class {
|
|
|
2349
2478
|
/**
|
|
2350
2479
|
* Issue swapped tokens for refresh flow
|
|
2351
2480
|
*/
|
|
2352
|
-
async issueSwappedTokensForRefresh(clientId, upstreamTokens, upstreamTokenKey) {
|
|
2481
|
+
async issueSwappedTokensForRefresh(clientId, upstreamTokens, upstreamTokenKey, clientAuthenticated) {
|
|
2353
2482
|
if (!this.jwtIssuer) {
|
|
2354
2483
|
throw new Error("JWT issuer not initialized");
|
|
2355
2484
|
}
|
|
@@ -2392,6 +2521,7 @@ var OAuthProxy = class {
|
|
|
2392
2521
|
await this.tokenStorage.save(
|
|
2393
2522
|
`mapping:${this.issuerNs}:${refreshJti}`,
|
|
2394
2523
|
{
|
|
2524
|
+
clientAuthenticated,
|
|
2395
2525
|
clientId,
|
|
2396
2526
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2397
2527
|
expiresAt: new Date(Date.now() + refreshTokenTtl * 1e3),
|
|
@@ -2508,6 +2638,15 @@ var OAuthProxy = class {
|
|
|
2508
2638
|
const rawJson = await response.json();
|
|
2509
2639
|
return tokenResponseSchema.parse(rawJson);
|
|
2510
2640
|
}
|
|
2641
|
+
/**
|
|
2642
|
+
* Storage key for the client binding of a passthrough-mode upstream refresh
|
|
2643
|
+
* token. Keyed by its hash: storage keys are not encrypted, and the token
|
|
2644
|
+
* itself is a live upstream credential.
|
|
2645
|
+
*/
|
|
2646
|
+
passthroughRefreshKey(refreshToken) {
|
|
2647
|
+
const digest = createHash3("sha256").update(refreshToken).digest("base64url");
|
|
2648
|
+
return `passthrough-refresh:${this.issuerNs}:${digest}`;
|
|
2649
|
+
}
|
|
2511
2650
|
/**
|
|
2512
2651
|
* Redirect to upstream OAuth provider
|
|
2513
2652
|
*/
|
|
@@ -2664,6 +2803,18 @@ var OAuthProxy = class {
|
|
|
2664
2803
|
ttl
|
|
2665
2804
|
);
|
|
2666
2805
|
}
|
|
2806
|
+
/**
|
|
2807
|
+
* Record which client a passthrough-mode upstream refresh token was handed
|
|
2808
|
+
* to. It lives as long as the upstream says the token does, or as the
|
|
2809
|
+
* configured refresh-token lifetime when it does not say.
|
|
2810
|
+
*/
|
|
2811
|
+
async savePassthroughRefreshBinding(refreshToken, binding, refreshExpiresIn) {
|
|
2812
|
+
await this.tokenStorage.save(
|
|
2813
|
+
this.passthroughRefreshKey(refreshToken),
|
|
2814
|
+
binding,
|
|
2815
|
+
refreshExpiresIn ?? this.config.refreshTokenTtl ?? DEFAULT_REFRESH_TOKEN_TTL
|
|
2816
|
+
);
|
|
2817
|
+
}
|
|
2667
2818
|
/**
|
|
2668
2819
|
* Start periodic cleanup of expired transactions and codes
|
|
2669
2820
|
*/
|
|
@@ -2791,6 +2942,21 @@ var isLoopbackRedirectUri = (uri) => {
|
|
|
2791
2942
|
return false;
|
|
2792
2943
|
}
|
|
2793
2944
|
};
|
|
2945
|
+
var isPublicClient = (client) => client.source === "cimd" || client.tokenEndpointAuthMethod === "none";
|
|
2946
|
+
var describeUnauthenticatedClient = (client) => {
|
|
2947
|
+
if (client.source === "cimd") {
|
|
2948
|
+
return "Client ID Metadata Document clients";
|
|
2949
|
+
}
|
|
2950
|
+
if (client.tokenEndpointAuthMethod === "none") {
|
|
2951
|
+
return 'clients registered with token_endpoint_auth_method "none"';
|
|
2952
|
+
}
|
|
2953
|
+
return "clients that do not authenticate with their client_secret";
|
|
2954
|
+
};
|
|
2955
|
+
var isTokenEndpointAuthMethod = (value) => TOKEN_ENDPOINT_AUTH_METHODS.includes(value);
|
|
2956
|
+
var secretsMatch = (presented, expected) => timingSafeEqual4(
|
|
2957
|
+
createHash3("sha256").update(presented).digest(),
|
|
2958
|
+
createHash3("sha256").update(expected).digest()
|
|
2959
|
+
);
|
|
2794
2960
|
var OAuthProxyError = class extends Error {
|
|
2795
2961
|
constructor(code, description, statusCode = 400) {
|
|
2796
2962
|
super(code);
|
|
@@ -3462,4 +3628,4 @@ export {
|
|
|
3462
3628
|
DiskStore,
|
|
3463
3629
|
JWKSVerifier
|
|
3464
3630
|
};
|
|
3465
|
-
//# sourceMappingURL=chunk-
|
|
3631
|
+
//# sourceMappingURL=chunk-ZVK5GKEO.js.map
|