openvibers/openvibe.exchange Commits
Open Exchange messages in Dock Chats (#137)
Changes
@@@ -78,6 +78,13 @@ server {proxy_pass http://127.0.0.1:5150;}++ # The Dock token is fetched on signed-in page views; give it the session probe's budget.++ location = /auth/navbar-token {++ limit_req zone=exchange_api burst=30 nodelay;++ limit_req_status 429;++ proxy_pass http://127.0.0.1:5150;++ }++location /auth/ {limit_req zone=exchange_auth burst=10 nodelay;limit_req_status 429;@@@ -167,7 +167,7 @@ async function createApp(opts = {}) {app.use(sso.middleware());// ── Sign-in (OAuth2 + PKCE client of OpenVibe.Network) ──-- app.use('/auth/', rateLimit({ windowMs: 15 * 60_000, limit: 60, standardHeaders: true, legacyHeaders: false }));++ app.use('/auth/', rateLimit({ windowMs: 15 * 60_000, limit: 60, skip: (req) => req.path === '/me' || req.path === '/navbar-token', standardHeaders: true, legacyHeaders: false }));app.use('/auth', sso.routes());{ const legal = require('openvibe-shared/legal'); app.get(legal.PATHS, legal.handler({ id: 'exchange', service: 'exchange', host: 'openvibe.exchange', name: 'OpenVibe.Exchange', profile: 'ugc' })); }@@@ -183,6 +183,16 @@ function createSso({ config, keys, fetchImpl = globalThis.fetch, now = () => Datreturn res.json({ user: meOf(claims) });});++ // The navbar needs a Network access token for the Dock. Keep /auth/me's++ // profile response token-free; this same-origin answer is never cached.++ r.get('/navbar-token', async (req, res) => {++ res.set('Cache-Control', 'private, no-store');++ const token = sso.extractToken(req);++ const claims = await sso.verify(token);++ if (!claims) return res.status(401).json({ error: 'Not signed in' });++ return res.json({ token, expires_at: claims.exp ? claims.exp * 1000 : null });++ });++// Sign-out stays a same-site action: another site cannot sign a person out.const sameOriginRequest = (req) => {const site = String(req.get('sec-fetch-site') || '');@@@ -71,6 +71,7 @@ function renderPage(o) {history: { type: 'page', title: o.title || SITE_NAME },silentLogin: `${o.config.baseUrl}/auth/login?silent=1&next={url}`,sessionUrl: '/auth/me',++ tokenUrl: '/auth/navbar-token',loginUrl: '/auth/login?next={path}',logoutUrl: '/auth/logout?next={path}',notificationsRealtime: true,@@@ -42,6 +42,11 @@ const { sanitizeNext } = require('../server/auth/sso');const me = await t.get('/auth/me', { cookie: `ov_token=${at}` });assert.strictEqual(me.json().user.username, 'kim');assert.ok(!me.text.includes(at), '/auth/me never returns the token');++ const nav = await t.get('/auth/navbar-token', { cookie: `ov_token=${at}` });++ assert.strictEqual(nav.status, 200);++ assert.strictEqual(nav.json().token, at, 'the Dock receives the verified Network token');++ assert.strictEqual(nav.headers.get('cache-control'), 'private, no-store');++ assert.strictEqual((await t.get('/auth/navbar-token')).status, 401, 'a guest receives no token');});await check('a wrong state, a verifier that does not match, or no flow cookie starts the sign-in once more', async () => {
@@ -78,6 +78,13 @@ server {
@@ -78,6 +78,13 @@ server {
proxy_pass http://127.0.0.1:5150;
proxy_pass http://127.0.0.1:5150;
}
}
+ # The Dock token is fetched on signed-in page views; give it the session probe's budget.
+ location = /auth/navbar-token {
+ limit_req zone=exchange_api burst=30 nodelay;
+ limit_req_status 429;
+ proxy_pass http://127.0.0.1:5150;
+ }
+
location /auth/ {
location /auth/ {
limit_req zone=exchange_auth burst=10 nodelay;
limit_req zone=exchange_auth burst=10 nodelay;
limit_req_status 429;
limit_req_status 429;
@@ -167,7 +167,7 @@ async function createApp(opts = {}) {
@@ -167,7 +167,7 @@ async function createApp(opts = {}) {
app.use(sso.middleware());
app.use(sso.middleware());
// ── Sign-in (OAuth2 + PKCE client of OpenVibe.Network) ──
// ── Sign-in (OAuth2 + PKCE client of OpenVibe.Network) ──
- app.use('/auth/', rateLimit({ windowMs: 15 * 60_000, limit: 60, standardHeaders: true, legacyHeaders: false }));
+ app.use('/auth/', rateLimit({ windowMs: 15 * 60_000, limit: 60, skip: (req) => req.path === '/me' || req.path === '/navbar-token', standardHeaders: true, legacyHeaders: false }));
app.use('/auth', sso.routes());
app.use('/auth', sso.routes());
{ const legal = require('openvibe-shared/legal'); app.get(legal.PATHS, legal.handler({ id: 'exchange', service: 'exchange', host: 'openvibe.exchange', name: 'OpenVibe.Exchange', profile: 'ugc' })); }
{ const legal = require('openvibe-shared/legal'); app.get(legal.PATHS, legal.handler({ id: 'exchange', service: 'exchange', host: 'openvibe.exchange', name: 'OpenVibe.Exchange', profile: 'ugc' })); }
@@ -183,6 +183,16 @@ function createSso({ config, keys, fetchImpl = globalThis.fetch, now = () => Dat
@@ -183,6 +183,16 @@ function createSso({ config, keys, fetchImpl = globalThis.fetch, now = () => Dat
return res.json({ user: meOf(claims) });
return res.json({ user: meOf(claims) });
});
});
+ // The navbar needs a Network access token for the Dock. Keep /auth/me's
+ // profile response token-free; this same-origin answer is never cached.
+ r.get('/navbar-token', async (req, res) => {
+ res.set('Cache-Control', 'private, no-store');
+ const token = sso.extractToken(req);
+ const claims = await sso.verify(token);
+ if (!claims) return res.status(401).json({ error: 'Not signed in' });
+ return res.json({ token, expires_at: claims.exp ? claims.exp * 1000 : null });
+ });
+
// Sign-out stays a same-site action: another site cannot sign a person out.
// Sign-out stays a same-site action: another site cannot sign a person out.
const sameOriginRequest = (req) => {
const sameOriginRequest = (req) => {
const site = String(req.get('sec-fetch-site') || '');
const site = String(req.get('sec-fetch-site') || '');
@@ -71,6 +71,7 @@ function renderPage(o) {
@@ -71,6 +71,7 @@ function renderPage(o) {
history: { type: 'page', title: o.title || SITE_NAME },
history: { type: 'page', title: o.title || SITE_NAME },
silentLogin: `${o.config.baseUrl}/auth/login?silent=1&next={url}`,
silentLogin: `${o.config.baseUrl}/auth/login?silent=1&next={url}`,
sessionUrl: '/auth/me',
sessionUrl: '/auth/me',
+ tokenUrl: '/auth/navbar-token',
loginUrl: '/auth/login?next={path}',
loginUrl: '/auth/login?next={path}',
logoutUrl: '/auth/logout?next={path}',
logoutUrl: '/auth/logout?next={path}',
notificationsRealtime: true,
notificationsRealtime: true,
@@ -42,6 +42,11 @@ const { sanitizeNext } = require('../server/auth/sso');
@@ -42,6 +42,11 @@ const { sanitizeNext } = require('../server/auth/sso');
const me = await t.get('/auth/me', { cookie: `ov_token=${at}` });
const me = await t.get('/auth/me', { cookie: `ov_token=${at}` });
assert.strictEqual(me.json().user.username, 'kim');
assert.strictEqual(me.json().user.username, 'kim');
assert.ok(!me.text.includes(at), '/auth/me never returns the token');
assert.ok(!me.text.includes(at), '/auth/me never returns the token');
+ const nav = await t.get('/auth/navbar-token', { cookie: `ov_token=${at}` });
+ assert.strictEqual(nav.status, 200);
+ assert.strictEqual(nav.json().token, at, 'the Dock receives the verified Network token');
+ assert.strictEqual(nav.headers.get('cache-control'), 'private, no-store');
+ assert.strictEqual((await t.get('/auth/navbar-token')).status, 401, 'a guest receives no token');
});
});
await check('a wrong state, a verifier that does not match, or no flow cookie starts the sign-in once more', async () => {
await check('a wrong state, a verifier that does not match, or no flow cookie starts the sign-in once more', async () => {