mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
fix: Missing /mcp well-known routes (#11575)
This commit is contained in:
1 parent
0ce992e87a
commit
4ebb0e1790
2 files changed
+97
-20
No files matched your search
+51
-20
@@ -111,27 +111,58 @@ router.get("/locales/:lng.json", async (ctx) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/.well-known/oauth-authorization-server", async (ctx) => {
|
||||
const origin = ctx.request.URL.origin;
|
||||
const team = await getTeamFromContext(ctx, { includeStateCookie: false });
|
||||
const mcpEnabled = team?.getPreference(TeamPreference.MCP) ?? true;
|
||||
router.get(
|
||||
[
|
||||
"/.well-known/oauth-authorization-server",
|
||||
"/.well-known/oauth-authorization-server/mcp",
|
||||
],
|
||||
async (ctx) => {
|
||||
const origin = ctx.request.URL.origin;
|
||||
const team = await getTeamFromContext(ctx, { includeStateCookie: false });
|
||||
const mcpEnabled = team?.getPreference(TeamPreference.MCP) ?? true;
|
||||
|
||||
ctx.body = {
|
||||
issuer: origin,
|
||||
authorization_endpoint: `${origin}/oauth/authorize`,
|
||||
token_endpoint: `${origin}/oauth/token`,
|
||||
revocation_endpoint: `${origin}/oauth/revoke`,
|
||||
...(!env.OAUTH_DISABLE_DCR &&
|
||||
mcpEnabled && {
|
||||
registration_endpoint: `${origin}/oauth/register`,
|
||||
}),
|
||||
response_types_supported: ["code"],
|
||||
grant_types_supported: ["authorization_code", "refresh_token"],
|
||||
token_endpoint_auth_methods_supported: ["client_secret_post", "none"],
|
||||
code_challenge_methods_supported: ["S256"],
|
||||
scopes_supported: ["read", "write"],
|
||||
};
|
||||
});
|
||||
ctx.body = {
|
||||
issuer: origin,
|
||||
authorization_endpoint: `${origin}/oauth/authorize`,
|
||||
token_endpoint: `${origin}/oauth/token`,
|
||||
revocation_endpoint: `${origin}/oauth/revoke`,
|
||||
...(!env.OAUTH_DISABLE_DCR &&
|
||||
mcpEnabled && {
|
||||
registration_endpoint: `${origin}/oauth/register`,
|
||||
}),
|
||||
response_types_supported: ["code"],
|
||||
grant_types_supported: ["authorization_code", "refresh_token"],
|
||||
token_endpoint_auth_methods_supported: ["client_secret_post", "none"],
|
||||
code_challenge_methods_supported: ["S256"],
|
||||
scopes_supported: ["read", "write"],
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
router.get(
|
||||
[
|
||||
"/.well-known/oauth-protected-resource",
|
||||
"/.well-known/oauth-protected-resource/mcp",
|
||||
],
|
||||
async (ctx) => {
|
||||
const team = await getTeamFromContext(ctx, { includeStateCookie: false });
|
||||
const mcpEnabled = team?.getPreference(TeamPreference.MCP) ?? true;
|
||||
|
||||
if (!mcpEnabled) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
const origin = ctx.request.URL.origin;
|
||||
|
||||
ctx.body = {
|
||||
resource: `${origin}/mcp`,
|
||||
authorization_servers: [origin],
|
||||
scopes_supported: ["read", "write"],
|
||||
bearer_methods_supported: ["header"],
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/robots.txt", (ctx) => {
|
||||
ctx.body = robotsResponse();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import { OAuthClient } from "@server/models";
|
||||
import { buildTeam } from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
@@ -433,4 +434,49 @@ describe("GET /.well-known/oauth-authorization-server", () => {
|
||||
]);
|
||||
expect(body.code_challenge_methods_supported).toEqual(["S256"]);
|
||||
});
|
||||
|
||||
it("should return OAuth metadata at /mcp suffix path", async () => {
|
||||
const res = await server.get("/.well-known/oauth-authorization-server/mcp");
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
const body = await res.json();
|
||||
expect(body.issuer).toBeTruthy();
|
||||
expect(body.authorization_endpoint).toContain("/oauth/authorize");
|
||||
expect(body.token_endpoint).toContain("/oauth/token");
|
||||
});
|
||||
});
|
||||
|
||||
describe("GET /.well-known/oauth-protected-resource", () => {
|
||||
it("should return protected resource metadata", async () => {
|
||||
const res = await server.get("/.well-known/oauth-protected-resource");
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
const body = await res.json();
|
||||
expect(body.resource).toContain("/mcp");
|
||||
expect(body.authorization_servers).toHaveLength(1);
|
||||
expect(body.scopes_supported).toEqual(["read", "write"]);
|
||||
expect(body.bearer_methods_supported).toEqual(["header"]);
|
||||
});
|
||||
|
||||
it("should return protected resource metadata at /mcp suffix path", async () => {
|
||||
const res = await server.get("/.well-known/oauth-protected-resource/mcp");
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
const body = await res.json();
|
||||
expect(body.resource).toContain("/mcp");
|
||||
expect(body.authorization_servers).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("should return 404 when MCP is disabled", async () => {
|
||||
const team = await buildTeam({
|
||||
subdomain: faker.internet.domainWord(),
|
||||
preferences: { [TeamPreference.MCP]: false },
|
||||
});
|
||||
|
||||
const res = await server.get("/.well-known/oauth-protected-resource", {
|
||||
headers: { host: `${team.subdomain}.outline.dev` },
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(404);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user