mirror of
https://github.com/outline/outline.git
synced 2026-11-25 15:15:15 +03:00
fix: Align OAuth discovery metadata with RFC 8414 and RFC 9728 (#14324)
This commit is contained in:
1 parent
71af4d6901
commit
c8b79a3ccf
2 files changed
+38
-43
No files matched your search
@@ -6,42 +6,37 @@ import { getTeamFromContext } from "@server/utils/passport";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.get(
|
||||
[
|
||||
"/.well-known/oauth-authorization-server",
|
||||
"/.well-known/oauth-authorization-server/mcp",
|
||||
],
|
||||
async (ctx) => {
|
||||
const origin = OAuthHelper.getIssuer(ctx);
|
||||
const team = await getTeamFromContext(ctx, { includeOAuthState: false });
|
||||
const mcpEnabled = team?.getPreference(TeamPreference.MCP) ?? true;
|
||||
// The issuer has no path, so its metadata lives only at the root (RFC 8414 §3.1).
|
||||
router.get("/.well-known/oauth-authorization-server", async (ctx) => {
|
||||
const origin = OAuthHelper.getIssuer(ctx);
|
||||
const team = await getTeamFromContext(ctx, { includeOAuthState: 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`,
|
||||
// Registration needs a workspace, so it is not offered on the root
|
||||
// domain. Clients there use a client ID metadata document instead.
|
||||
...(!env.OAUTH_DISABLE_DCR &&
|
||||
team &&
|
||||
mcpEnabled && {
|
||||
registration_endpoint: `${origin}/oauth/register`,
|
||||
}),
|
||||
client_id_metadata_document_supported: mcpEnabled,
|
||||
response_types_supported: OAuthHelper.responseTypes,
|
||||
response_modes_supported: ["query"],
|
||||
grant_types_supported: OAuthHelper.grantTypes,
|
||||
token_endpoint_auth_methods_supported:
|
||||
OAuthHelper.tokenEndpointAuthMethods,
|
||||
revocation_endpoint_auth_methods_supported:
|
||||
OAuthHelper.tokenEndpointAuthMethods,
|
||||
code_challenge_methods_supported: ["S256"],
|
||||
scopes_supported: OAuthHelper.mcpScopes,
|
||||
};
|
||||
}
|
||||
);
|
||||
ctx.body = {
|
||||
issuer: origin,
|
||||
authorization_endpoint: `${origin}/oauth/authorize`,
|
||||
token_endpoint: `${origin}/oauth/token`,
|
||||
revocation_endpoint: `${origin}/oauth/revoke`,
|
||||
// Registration needs a workspace, so it is not offered on the root
|
||||
// domain. Clients there use a client ID metadata document instead.
|
||||
...(!env.OAUTH_DISABLE_DCR &&
|
||||
team &&
|
||||
mcpEnabled && {
|
||||
registration_endpoint: `${origin}/oauth/register`,
|
||||
}),
|
||||
client_id_metadata_document_supported: mcpEnabled,
|
||||
response_types_supported: OAuthHelper.responseTypes,
|
||||
response_modes_supported: ["query"],
|
||||
grant_types_supported: OAuthHelper.grantTypes,
|
||||
token_endpoint_auth_methods_supported: OAuthHelper.tokenEndpointAuthMethods,
|
||||
revocation_endpoint_auth_methods_supported:
|
||||
OAuthHelper.tokenEndpointAuthMethods,
|
||||
code_challenge_methods_supported: ["S256"],
|
||||
scopes_supported: OAuthHelper.mcpScopes,
|
||||
};
|
||||
});
|
||||
|
||||
// The resource must match the path the document is requested at (RFC 9728 §3.3).
|
||||
router.get(
|
||||
[
|
||||
"/.well-known/oauth-protected-resource",
|
||||
@@ -57,9 +52,11 @@ router.get(
|
||||
}
|
||||
|
||||
const origin = OAuthHelper.getIssuer(ctx);
|
||||
const path = ctx.path.endsWith("/mcp") ? "/mcp" : "";
|
||||
|
||||
ctx.body = {
|
||||
resource: `${origin}/mcp`,
|
||||
resource: `${origin}${path}`,
|
||||
resource_name: env.APP_NAME,
|
||||
authorization_servers: [origin],
|
||||
scopes_supported: OAuthHelper.mcpScopes,
|
||||
bearer_methods_supported: ["header"],
|
||||
|
||||
@@ -613,14 +613,10 @@ describe("GET /.well-known/oauth-authorization-server", () => {
|
||||
expect(body.client_id_metadata_document_supported).toBe(false);
|
||||
});
|
||||
|
||||
it("should return OAuth metadata at /mcp suffix path", async () => {
|
||||
it("should not serve 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");
|
||||
expect(res.status).toEqual(404);
|
||||
});
|
||||
|
||||
it("should include port in URLs when configured with a custom port (self-hosted)", async () => {
|
||||
@@ -648,7 +644,8 @@ describe("GET /.well-known/oauth-protected-resource", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
const body = await res.json();
|
||||
expect(body.resource).toContain("/mcp");
|
||||
expect(body.resource).toEqual(body.authorization_servers[0]);
|
||||
expect(body.resource_name).toEqual("Outline");
|
||||
expect(body.authorization_servers).toHaveLength(1);
|
||||
expect(body.scopes_supported).toEqual(["read", "write"]);
|
||||
expect(body.bearer_methods_supported).toEqual(["header"]);
|
||||
@@ -659,7 +656,8 @@ describe("GET /.well-known/oauth-protected-resource", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
const body = await res.json();
|
||||
expect(body.resource).toContain("/mcp");
|
||||
expect(body.resource).toEqual(`${body.authorization_servers[0]}/mcp`);
|
||||
expect(body.resource_name).toEqual("Outline");
|
||||
expect(body.authorization_servers).toHaveLength(1);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user