@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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withoutTrailingSlash
3
- } from "./chunk-WOQXAQIG.js";
3
+ } from "./chunk-PXH56Q3F.js";
4
4
  import {
5
5
  formatBytes,
6
6
  ownKeysOnly,
@@ -1690,4 +1690,4 @@ export {
1690
1690
  ServerState,
1691
1691
  ViteMCP
1692
1692
  };
1693
- //# sourceMappingURL=chunk-2JOXLIMJ.js.map
1693
+ //# sourceMappingURL=chunk-LZTRZ62V.js.map
@@ -2095,7 +2095,7 @@ var OAuthProxy = 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 {
@@ -2299,7 +2299,7 @@ var OAuthProxy = 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 {
@@ -2685,6 +2685,40 @@ var OAuthProxy = class {
2685
2685
  const digest = createHash3("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 = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
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: 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 = 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 {
@@ -3110,11 +3144,12 @@ var AuthProvider = 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 = /^bearer +(\S.*)$/i.exec(
3148
+ request2.headers.get("authorization") ?? ""
3149
+ )?.[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;
@@ -3719,4 +3754,4 @@ export {
3719
3754
  DiskStore,
3720
3755
  JWKSVerifier
3721
3756
  };
3722
- //# sourceMappingURL=chunk-WOQXAQIG.js.map
3757
+ //# sourceMappingURL=chunk-PXH56Q3F.js.map