MCPcopy Create free account
hub / github.com/MemTensor/MemOS / enforceApiKey

Function enforceApiKey

apps/memos-local-plugin/server/middleware/auth.ts:17–29  ·  view source on GitHub ↗
(
  req: IncomingMessage,
  res: ServerResponse,
  apiKey: string,
)

Source from the content-addressed store, hash-verified

15import { writeJson } from "./io.js";
16
17export function enforceApiKey(
18 req: IncomingMessage,
19 res: ServerResponse,
20 apiKey: string,
21): boolean {
22 const presented =
23 extractBearer(req.headers["authorization"]) ??
24 headerValue(req.headers["x-api-key"]) ??
25 "";
26 if (presented === apiKey) return true;
27 writeJson(res, 401, { error: { code: "unauthenticated", message: "api key required" } });
28 return false;
29}
30
31function extractBearer(h: string | string[] | undefined): string | undefined {
32 const v = headerValue(h);

Callers 1

dispatchFunction · 0.85

Calls 3

extractBearerFunction · 0.85
headerValueFunction · 0.85
writeJsonFunction · 0.85

Tested by

no test coverage detected