Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(federation): point the 401 challenge at the metadata for the requested path

ruv005dbf186f8d
diff --git a/plugins/ruflo-chatgpt-federation/src/server.mjs b/plugins/ruflo-chatgpt-federation/src/server.mjs
index 3e4ae0f6cf..d3355dc2fe 100644
--- a/plugins/ruflo-chatgpt-federation/src/server.mjs
+++ b/plugins/ruflo-chatgpt-federation/src/server.mjs
@@ -80,7 +80,13 @@ export function createPublisherService({ relay, keyPath, port } = {}) {
// asserted, which is only acceptable while OAuth is not yet enforced.
const OAUTH_CLIENT_ID = (process.env.CGF_OAUTH_CLIENT_ID || '').trim();
const resourceUrl = () => (process.env.CGF_PUBLIC_URL || '').replace(/\/$/, '');
- const prmUrl = () => `${resourceUrl()}/.well-known/oauth-protected-resource`;
+ // RFC 9728 §5.1: point at the metadata for the resource the client actually
+ // requested. A client using <base>/mcp must be sent to the /mcp-suffixed
+ // document, whose `resource` is <base>/mcp — sending it to the bare document
+ // hands back an identifier it never asked about, which is the same mismatch
+ // that silently stalls setup.
+ const prmUrl = (pathname) => `${resourceUrl()}/.well-known/oauth-protected-resource`
+ + (pathname === '/mcp' ? '/mcp' : '');
/**
* Resolve what this request is allowed to do.
@@ -174,7 +180,7 @@ export function createPublisherService({ relay, keyPath, port } = {}) {
tools: ['federation_identity', 'channel_sync', 'channel_publish'],
authorization: { type: 'oauth2', issuer: OAUTH_ISSUER, clientId: OAUTH_CLIENT_ID || null,
scopes: [SCOPE_READ, SCOPE_PUBLISH],
- protectedResourceMetadata: prmUrl(),
+ protectedResourceMetadata: prmUrl('/mcp'),
enforced: OAUTH_REQUIRED,
transitionalHeader: OAUTH_REQUIRED ? null : 'x-caller-token' } }));
}
@@ -207,7 +213,7 @@ export function createPublisherService({ relay, keyPath, port } = {}) {
if (auth.mode === 'denied') {
// 401 + WWW-Authenticate is what starts a client's OAuth discovery.
res.writeHead(401, { 'content-type': 'application/json',
- 'www-authenticate': challengeHeader(prmUrl(), { error: auth.error, description: auth.description }) });
+ 'www-authenticate': challengeHeader(prmUrl(url.pathname), { error: auth.error, description: auth.description }) });
return res.end(JSON.stringify({ error: auth.error, error_description: auth.description }));
}
const mcp = buildMcp(req, auth); const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
diff --git a/plugins/ruflo-chatgpt-federation/test/oauth.test.mjs b/plugins/ruflo-chatgpt-federation/test/oauth.test.mjs
index a82c2d3f8d..3b42d55893 100644
--- a/plugins/ruflo-chatgpt-federation/test/oauth.test.mjs
+++ b/plugins/ruflo-chatgpt-federation/test/oauth.test.mjs
@@ -108,7 +108,8 @@ test('with OAuth required, an unauthenticated call gets 401 and a discovery poin
await withService(as, { required: true, publicUrl: 'https://cgf.example' }, async (port) => {
const r = await call(port, 'federation_identity');
assert.equal(r.status, 401);
- assert.match(r.wwwAuth, /resource_metadata="https:\/\/cgf\.example\/\.well-known\/oauth-protected-resource"/);
+ // …/mcp was requested, so the pointer carries the /mcp suffix.
+ assert.match(r.wwwAuth, /resource_metadata="https:\/\/cgf\.example\/\.well-known\/oauth-protected-resource\/mcp"/);
});
} finally { as.close(); }
});
@@ -227,7 +228,7 @@ test('the service info advertises the authorization server and enforcement state
assert.equal(info.authorization.issuer, as.issuer);
assert.deepEqual(info.authorization.scopes, [SCOPE_READ, SCOPE_PUBLISH]);
assert.equal(info.authorization.protectedResourceMetadata,
- 'https://cgf.example/.well-known/oauth-protected-resource');
+ 'https://cgf.example/.well-known/oauth-protected-resource/mcp');
assert.equal(info.authorization.enforced, required);
assert.equal(info.authorization.transitionalHeader, required ? null : 'x-caller-token');
});
@@ -357,3 +358,17 @@ test('the auth-mode log line never contains token material', async () => {
});
} finally { console.log = orig; as.close(); }
});
+
+test('the 401 challenge points at the metadata for the path that was requested', async () => {
+ const as = await fakeAuthServer();
+ try {
+ await withService(as, { required: true, publicUrl: 'https://cgf.example' }, async (port) => {
+ const r = await call(port, 'federation_identity');
+ assert.equal(r.status, 401);
+ // …/mcp was requested, so the pointer must be the /mcp-suffixed document,
+ // whose `resource` matches the identifier the client is using.
+ assert.match(r.wwwAuth || '',
+ /resource_metadata="https:\/\/cgf\.example\/\.well-known\/oauth-protected-resource\/mcp"/);
+ });
+ } finally { as.close(); }
+});