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(ruflo-x-gateway): advertise offline_access so OAuth clients can refresh silently

r29b9ea9abef8
diff --git a/plugins/ruflo-x-gateway/claude-directory-submission.json b/plugins/ruflo-x-gateway/claude-directory-submission.json
index 9d2f754d2d..77dd346675 100644
--- a/plugins/ruflo-x-gateway/claude-directory-submission.json
+++ b/plugins/ruflo-x-gateway/claude-directory-submission.json
@@ -18,7 +18,7 @@
"transport": "streamable_http",
"authentication": "oauth_2_1",
"protected_resource_metadata": "https://x.ruv.io/.well-known/oauth-protected-resource/claude/mcp",
- "scopes": ["swarm:read", "swarm:publish"],
+ "scopes": ["swarm:read", "swarm:publish", "offline_access"],
"anonymous_reads": true,
"oauth_required_for_writes": true
},
diff --git a/plugins/ruflo-x-gateway/package-lock.json b/plugins/ruflo-x-gateway/package-lock.json
index 88bf627e06..569701d7af 100644
--- a/plugins/ruflo-x-gateway/package-lock.json
+++ b/plugins/ruflo-x-gateway/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@ruflo/x-gateway",
- "version": "0.8.1",
+ "version": "0.9.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@ruflo/x-gateway",
- "version": "0.8.1",
+ "version": "0.9.0",
"license": "MIT",
"dependencies": {
"@google-cloud/firestore": "^9.2.0",
diff --git a/plugins/ruflo-x-gateway/src/oauth.mjs b/plugins/ruflo-x-gateway/src/oauth.mjs
index b551a81a3f..6bf539fed5 100644
--- a/plugins/ruflo-x-gateway/src/oauth.mjs
+++ b/plugins/ruflo-x-gateway/src/oauth.mjs
@@ -21,6 +21,17 @@ import { createRemoteJWKSet, jwtVerify } from 'jose';
export const SCOPE_READ = 'swarm:read';
export const SCOPE_PUBLISH = 'swarm:publish';
+// Standard OIDC scope requesting a refresh_token (RFC 6749 + OIDC Core §11).
+// `auth.cognitum.one` advertises `refresh_token` in grant_types_supported and
+// `offline_access` in scopes_supported (its own discovery doc), but only
+// issues a refresh_token when a client actually requests this scope. Without
+// it, every access token this resource accepts is the only credential a
+// client ever gets, so its own short expiry forces a full browser
+// authorization_code+PKCE dance again each time it lapses. Advertising it
+// here lets a spec-compliant client (RFC 9728: request only scopes this
+// resource says it supports) ask for it and refresh silently instead.
+export const SCOPE_OFFLINE = 'offline_access';
+
/**
* RFC 9728 protected-resource metadata. A client that gets a 401 from /mcp reads
* this to learn which authorization server to go to.
@@ -29,7 +40,7 @@ export function protectedResourceMetadata({ resource, issuer }) {
return {
resource,
authorization_servers: [issuer],
- scopes_supported: [SCOPE_READ, SCOPE_PUBLISH],
+ scopes_supported: [SCOPE_READ, SCOPE_PUBLISH, SCOPE_OFFLINE],
bearer_methods_supported: ['header'],
resource_documentation: `${resource}/`,
};
diff --git a/plugins/ruflo-x-gateway/src/server.mjs b/plugins/ruflo-x-gateway/src/server.mjs
index 4344a0bb62..4f8adbe4c1 100644
--- a/plugins/ruflo-x-gateway/src/server.mjs
+++ b/plugins/ruflo-x-gateway/src/server.mjs
@@ -27,7 +27,7 @@ import { askSeraphina } from './seraphina.mjs';
import { privacyPage, termsPage, supportPage } from './public-pages.mjs';
import { fenceUntrusted, untrustedToolResult } from './untrusted.mjs';
import { createGithubQuery, errorPayload } from './github-query.mjs';
-import { protectedResourceMetadata, challengeHeader, verifyAccessToken, hasScope, SCOPE_READ, SCOPE_PUBLISH } from './oauth.mjs';
+import { protectedResourceMetadata, challengeHeader, verifyAccessToken, hasScope, SCOPE_READ, SCOPE_PUBLISH, SCOPE_OFFLINE } from './oauth.mjs';
import { createHash } from 'node:crypto';
import { registrationFromEnv, RegistrationError } from './registration.mjs';
@@ -439,7 +439,7 @@ export function createGateway({ relay, keyFile, port, registration, github: gith
return res.end(JSON.stringify({ service: 'ruflo-x-gateway', version: VERSION, mcp: '/mcp', publicMcp: '/chatgpt/mcp', claudeMcp: '/claude/mcp',
registration: enrollment.info(), pages: { privacy: '/privacy', terms: '/terms', support: '/support' }, ws: ['/', '/relay'], relay: RELAY, canonicalRelay: RELAY, legacyRelay: LEGACY_RELAY, authNote: 'When connecting via wss://x.ruv.io, sign the NIP-42 AUTH `relay` tag with canonicalRelay (the relay verifies it strictly).', gatewayPubkey: pubkey, resources: ['ruv://federation/registry', 'ruv://federation/onboarding', 'ruv://swarm/roster', 'ruv://claims/board', 'ruv://swarm/channels'],
authorization: { type: 'oauth2', issuer: OAUTH_ISSUER, clientId: OAUTH_CLIENT_ID || null,
- scopes: [SCOPE_READ, SCOPE_PUBLISH], protectedResourceMetadata: prmUrl('/chatgpt/mcp') } })); }
+ scopes: [SCOPE_READ, SCOPE_PUBLISH, SCOPE_OFFLINE], protectedResourceMetadata: prmUrl('/chatgpt/mcp') } })); }
// ---- OpenAI app-review surface ----
// /.well-known/openai-apps-challenge proves domain control. The value lives
// ONLY in the environment (secret manager in production): it is never
@@ -473,7 +473,7 @@ export function createGateway({ relay, keyFile, port, registration, github: gith
...registryDoc(mcpPath), service: 'ruflo-x-gateway', version: VERSION,
protocol: 'mcp', transport: 'streamable-http', endpoint: `${PUBLIC_URL}${mcpPath}`, methods: ['POST'],
authorization: { type: 'oauth2', issuer: OAUTH_ISSUER, clientId: OAUTH_CLIENT_ID || null,
- scopes: [SCOPE_READ, SCOPE_PUBLISH], protectedResourceMetadata: prmUrl(mcpPath) },
+ scopes: [SCOPE_READ, SCOPE_PUBLISH, SCOPE_OFFLINE], protectedResourceMetadata: prmUrl(mcpPath) },
}));
}
// Legacy /mcp keeps the full surface, including the admin-argument tools that
diff --git a/plugins/ruflo-x-gateway/test/oauth.test.mjs b/plugins/ruflo-x-gateway/test/oauth.test.mjs
index 44a656ff72..9755e0be02 100644
--- a/plugins/ruflo-x-gateway/test/oauth.test.mjs
+++ b/plugins/ruflo-x-gateway/test/oauth.test.mjs
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { generateKeyPair, exportJWK, SignJWT } from 'jose';
import { createGateway } from '../src/server.mjs';
-import { protectedResourceMetadata, SCOPE_READ, SCOPE_PUBLISH } from '../src/oauth.mjs';
+import { protectedResourceMetadata, SCOPE_READ, SCOPE_PUBLISH, SCOPE_OFFLINE } from '../src/oauth.mjs';
const CLIENT_ID = 'ruflo-x-gateway';
@@ -61,12 +61,27 @@ const toolText = (r) => r.body?.result?.content?.[0]?.text ?? JSON.stringify(r.b
test('the gateway advertises its own scopes, not the connector\'s', () => {
const m = protectedResourceMetadata({ resource: 'https://x.example', issuer: 'https://auth.example' });
- assert.deepEqual(m.scopes_supported, ['swarm:read', 'swarm:publish']);
+ assert.deepEqual(m.scopes_supported, ['swarm:read', 'swarm:publish', 'offline_access']);
// Sharing federation:* would be safe (audience pinning is what isolates), but
// distinct scopes keep a consent screen honest about what this resource grants.
assert.ok(!m.scopes_supported.some((s) => s.startsWith('federation:')));
});
+test('the gateway advertises offline_access so a compliant client can refresh without re-auth', () => {
+ // auth.cognitum.one only issues a refresh_token when a client requests this
+ // scope (confirmed against its own /.well-known/openid-configuration:
+ // grant_types_supported includes refresh_token, scopes_supported includes
+ // offline_access). RFC 9728 has a client request only scopes this resource's
+ // metadata says it supports, so omitting it here was the actual cause of a
+ // full browser re-auth every time the short-lived access token expired.
+ const m = protectedResourceMetadata({ resource: 'https://x.example', issuer: 'https://auth.example' });
+ assert.ok(m.scopes_supported.includes(SCOPE_OFFLINE));
+ assert.equal(SCOPE_OFFLINE, 'offline_access');
+ // offline_access must never gate a tool call the way SCOPE_READ/SCOPE_PUBLISH
+ // do — it only controls refresh_token issuance at the authorization server.
+ assert.ok(![SCOPE_READ, SCOPE_PUBLISH].includes(SCOPE_OFFLINE));
+});
+
test('discovery echoes the identifier the client asked about', async () => {
const as = await fakeAuthServer();
try {