mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 14:01:16 -07:00
Change: just require auth for MCP
This commit is contained in:
@@ -61,10 +61,6 @@ function requiredToken() {
|
||||
return process.env.HOMEPAGE_MCP_TOKEN;
|
||||
}
|
||||
|
||||
function authEnabled() {
|
||||
return Boolean(process.env.HOMEPAGE_AUTH_ENABLED);
|
||||
}
|
||||
|
||||
function jsonRpcResult(id, result) {
|
||||
return { jsonrpc: "2.0", id, result };
|
||||
}
|
||||
@@ -447,10 +443,6 @@ export function mcpTokenAuthorized(req) {
|
||||
return authHeader === `Bearer ${token}` || req.headers["x-homepage-mcp-token"] === token;
|
||||
}
|
||||
|
||||
export function mcpAuthorized(req) {
|
||||
return mcpTokenAuthorized(req) || (!requiredToken() && !authEnabled());
|
||||
}
|
||||
|
||||
export function handleMcpRequest(message) {
|
||||
if (!message || message.jsonrpc !== "2.0" || typeof message.method !== "string") {
|
||||
return jsonRpcError(message?.id, -32600, "Invalid JSON-RPC request");
|
||||
|
||||
@@ -617,19 +617,14 @@ describe("utils/mcp/homepage-mcp", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("checks MCP token and auth mode authorization", async () => {
|
||||
it("requires a matching MCP token for token authorization", async () => {
|
||||
const mod = await loadMcpWithConfigDir(mkdtempSync(path.join(tmpdir(), "homepage-mcp-test-")));
|
||||
|
||||
expect(mod.mcpTokenAuthorized({ headers: {} })).toBe(false);
|
||||
expect(mod.mcpAuthorized({ headers: {} })).toBe(true);
|
||||
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
expect(mod.mcpAuthorized({ headers: {} })).toBe(false);
|
||||
|
||||
process.env.HOMEPAGE_MCP_TOKEN = "secret";
|
||||
expect(mod.mcpTokenAuthorized({ headers: { authorization: "Bearer secret" } })).toBe(true);
|
||||
expect(mod.mcpTokenAuthorized({ headers: { "x-homepage-mcp-token": "secret" } })).toBe(true);
|
||||
expect(mod.mcpTokenAuthorized({ headers: { authorization: "Bearer wrong" } })).toBe(false);
|
||||
expect(mod.mcpAuthorized({ headers: { authorization: "Bearer secret" } })).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user