@vitemcp/server 1.9.8 → 1.9.10

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-76HUSLES.js";
3
+ } from "./chunk-ZVK5GKEO.js";
4
4
  import {
5
5
  formatBytes,
6
6
  ownKeysOnly,
@@ -106,6 +106,27 @@ var noStore = {
106
106
  "Cache-Control": "no-store",
107
107
  Pragma: "no-cache"
108
108
  };
109
+ var invalidClientHeaders = {
110
+ ...noStore,
111
+ "WWW-Authenticate": 'Basic realm="oauth", charset="UTF-8"'
112
+ };
113
+ var parseBasicCredentials = (authorization) => {
114
+ const decoded = Buffer.from(authorization.slice(6).trim(), "base64").toString(
115
+ "utf8"
116
+ );
117
+ const separator = decoded.indexOf(":");
118
+ if (separator <= 0) {
119
+ return null;
120
+ }
121
+ try {
122
+ return {
123
+ clientId: decodeURIComponent(decoded.slice(0, separator)),
124
+ clientSecret: decodeURIComponent(decoded.slice(separator + 1))
125
+ };
126
+ } catch {
127
+ return null;
128
+ }
129
+ };
109
130
  var toSnakeCase = (value) => {
110
131
  if (!value || typeof value !== "object" || Array.isArray(value)) {
111
132
  return value;
@@ -173,21 +194,47 @@ var createOAuthRouter = (options) => {
173
194
  const params = Object.fromEntries(new URLSearchParams(text).entries());
174
195
  const authHeader = raw.headers.get("authorization");
175
196
  if (authHeader?.toLowerCase().startsWith("basic ")) {
176
- const decoded = Buffer.from(authHeader.slice(6), "base64").toString(
177
- "utf8"
178
- );
179
- const separator = decoded.indexOf(":");
180
- if (separator !== -1) {
181
- params.client_id ||= decodeURIComponent(decoded.slice(0, separator));
182
- params.client_secret ||= decodeURIComponent(
183
- decoded.slice(separator + 1)
197
+ const credentials = parseBasicCredentials(authHeader);
198
+ if (!credentials) {
199
+ return c.json(
200
+ {
201
+ error: "invalid_client",
202
+ error_description: "Malformed Basic Authorization header"
203
+ },
204
+ 401,
205
+ invalidClientHeaders
206
+ );
207
+ }
208
+ if (params.client_secret !== void 0) {
209
+ return c.json(
210
+ {
211
+ error: "invalid_request",
212
+ error_description: "Send client credentials in the Authorization header or the request body, not both"
213
+ },
214
+ 400,
215
+ noStore
184
216
  );
185
217
  }
218
+ if (params.client_id !== void 0 && params.client_id !== credentials.clientId) {
219
+ return c.json(
220
+ {
221
+ error: "invalid_request",
222
+ error_description: "client_id in the request body does not match the Authorization header"
223
+ },
224
+ 400,
225
+ noStore
226
+ );
227
+ }
228
+ params.client_id = credentials.clientId;
229
+ params.client_secret = credentials.clientSecret;
186
230
  }
187
231
  const result = params.grant_type === "refresh_token" ? await proxy.exchangeRefreshToken(params) : await proxy.exchangeAuthorizationCode(params);
188
232
  return c.json(result, 200, noStore);
189
233
  } catch (error) {
190
234
  const { body, status } = errorResponse(error);
235
+ if (body.error === "invalid_client") {
236
+ return c.json(body, 401, invalidClientHeaders);
237
+ }
191
238
  return c.json(body, status, noStore);
192
239
  }
193
240
  });
@@ -1627,4 +1674,4 @@ export {
1627
1674
  ServerState,
1628
1675
  ViteMCP
1629
1676
  };
1630
- //# sourceMappingURL=chunk-QZ6S3FM5.js.map
1677
+ //# sourceMappingURL=chunk-UVKIOOZA.js.map