@vitemcp/server 1.9.15 → 1.9.16

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.
@@ -2095,7 +2095,7 @@ var OAuthProxy = (_class4 = class {
2095
2095
  let errorCode = "server_error";
2096
2096
  let errorDescription;
2097
2097
  try {
2098
- const error = await tokenResponse.json();
2098
+ const error = await this.readUpstreamError(tokenResponse);
2099
2099
  errorCode = error.error || "server_error";
2100
2100
  errorDescription = error.error_description;
2101
2101
  } catch (e7) {
@@ -2299,7 +2299,7 @@ var OAuthProxy = (_class4 = class {
2299
2299
  let errorCode = "invalid_grant";
2300
2300
  let errorDescription;
2301
2301
  try {
2302
- const error = await tokenResponse.json();
2302
+ const error = await this.readUpstreamError(tokenResponse);
2303
2303
  errorCode = error.error || "invalid_grant";
2304
2304
  errorDescription = error.error_description;
2305
2305
  } catch (e8) {
@@ -2685,6 +2685,40 @@ var OAuthProxy = (_class4 = class {
2685
2685
  const digest = _crypto.createHash.call(void 0, "sha256").update(refreshToken).digest("base64url");
2686
2686
  return `passthrough-refresh:${this.issuerNs}:${digest}`;
2687
2687
  }
2688
+ /**
2689
+ * What a refusal from the token endpoint says: the `error` and
2690
+ * `error_description` RFC 6749 §5.2 gives it.
2691
+ *
2692
+ * §5.2 sends them as JSON, but a provider that answers a successful request
2693
+ * with a form — GitHub, by default — may refuse with one too, and read as
2694
+ * JSON that lost the provider's own code and description to a bare HTTP
2695
+ * status.
2696
+ *
2697
+ * What parses as JSON is read as JSON, whatever the response declares, as
2698
+ * every refusal was before. A form is read only when the response declares
2699
+ * one, by its media type alone: a 502 page can name that type in a parameter
2700
+ * and carry `error=` in a link, and is no provider's refusal. Rejects when
2701
+ * the body is neither, and the caller falls back to the HTTP status.
2702
+ */
2703
+ async readUpstreamError(response) {
2704
+ const text = await response.text();
2705
+ try {
2706
+ return JSON.parse(text);
2707
+ } catch (cause) {
2708
+ const mediaType = _optionalChain([response, 'access', _24 => _24.headers, 'access', _25 => _25.get, 'call', _26 => _26("content-type"), 'optionalAccess', _27 => _27.split, 'call', _28 => _28(";", 1), 'access', _29 => _29[0], 'optionalAccess', _30 => _30.trim, 'call', _31 => _31(), 'access', _32 => _32.toLowerCase, 'call', _33 => _33()]);
2709
+ if (mediaType === "application/x-www-form-urlencoded") {
2710
+ const params = new URLSearchParams(text);
2711
+ const error = params.get("error");
2712
+ if (error) {
2713
+ return {
2714
+ error,
2715
+ error_description: _nullishCoalesce(params.get("error_description"), () => ( void 0))
2716
+ };
2717
+ }
2718
+ }
2719
+ throw cause;
2720
+ }
2721
+ }
2688
2722
  /**
2689
2723
  * Send the user's browser back to the client's registered callback with how
2690
2724
  * its request came out: a code, or an error (RFC 6749 §4.1.2). The `state`
@@ -2770,7 +2804,7 @@ var OAuthProxy = (_class4 = class {
2770
2804
  let errorCode = "invalid_grant";
2771
2805
  let errorDescription = "Upstream refresh failed";
2772
2806
  try {
2773
- const error = await tokenResponse.json();
2807
+ const error = await this.readUpstreamError(tokenResponse);
2774
2808
  errorCode = error.error || "invalid_grant";
2775
2809
  errorDescription = error.error_description || "Upstream refresh failed";
2776
2810
  } catch (e10) {
@@ -2911,7 +2945,7 @@ var OAuthProxy = (_class4 = class {
2911
2945
  this.cleanupInterval = setInterval(() => {
2912
2946
  this.cleanup();
2913
2947
  }, 6e4);
2914
- _optionalChain([this, 'access', _24 => _24.cleanupInterval, 'access', _25 => _25.unref, 'optionalCall', _26 => _26()]);
2948
+ _optionalChain([this, 'access', _34 => _34.cleanupInterval, 'access', _35 => _35.unref, 'optionalCall', _36 => _36()]);
2915
2949
  }
2916
2950
  /**
2917
2951
  * PKCE challenge methods this proxy accepts, advertised in the authorization
@@ -3110,11 +3144,12 @@ var AuthProvider = (_class5 = class {
3110
3144
  if (!request2) {
3111
3145
  return void 0;
3112
3146
  }
3113
- const authHeader = request2.headers.get("authorization");
3114
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
3147
+ const token = _optionalChain([/^bearer +(\S.*)$/i, 'access', _37 => _37.exec, 'call', _38 => _38(
3148
+ _nullishCoalesce(request2.headers.get("authorization"), () => ( ""))
3149
+ ), 'optionalAccess', _39 => _39[1]]);
3150
+ if (!token) {
3115
3151
  return void 0;
3116
3152
  }
3117
- const token = authHeader.slice(7);
3118
3153
  const upstreamTokens = await this.proxy.loadUpstreamTokens(token);
3119
3154
  if (!upstreamTokens) {
3120
3155
  return void 0;
@@ -3140,7 +3175,7 @@ var AuthProvider = (_class5 = class {
3140
3175
  */
3141
3176
  destroy() {
3142
3177
  this._destroyed = true;
3143
- _optionalChain([this, 'access', _27 => _27._proxy, 'optionalAccess', _28 => _28.destroy, 'call', _29 => _29()]);
3178
+ _optionalChain([this, 'access', _40 => _40._proxy, 'optionalAccess', _41 => _41.destroy, 'call', _42 => _42()]);
3144
3179
  this._proxy = void 0;
3145
3180
  }
3146
3181
  /**
@@ -3355,7 +3390,7 @@ var DiskStore = (_class6 = class {
3355
3390
  this.cleanupInterval = setInterval(() => {
3356
3391
  void this.cleanup();
3357
3392
  }, cleanupIntervalMs);
3358
- _optionalChain([this, 'access', _30 => _30.cleanupInterval, 'access', _31 => _31.unref, 'optionalCall', _32 => _32()]);
3393
+ _optionalChain([this, 'access', _43 => _43.cleanupInterval, 'access', _44 => _44.unref, 'optionalCall', _45 => _45()]);
3359
3394
  }
3360
3395
  /**
3361
3396
  * Clean up expired entries.
@@ -3719,4 +3754,4 @@ Original error: ${error.message}`
3719
3754
 
3720
3755
 
3721
3756
  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;
3722
- //# sourceMappingURL=chunk-7XWK66ZT.cjs.map
3757
+ //# sourceMappingURL=chunk-TWYBLPRQ.cjs.map