openvibers/openvibe.services Commits
Open Services messages in Dock Chats (#250)
Changes
@@@ -90,6 +90,13 @@ server {proxy_pass http://127.0.0.1:4930;}++ # Give the Dock token the session probe's rate-limit budget.++ location = /auth/navbar-token {++ limit_req zone=ovservices_api burst=30 nodelay;++ limit_req_status 429;++ proxy_pass http://127.0.0.1:4930;++ }++location /auth/ {limit_req zone=ovservices_auth burst=10 nodelay;limit_req_status 429;@@@ -213,7 +213,7 @@ async function createApp(opts = {}) {// ── Sign-in (OAuth2 + PKCE client of OpenVibe.Network) ──// /auth/me is the navbar's who-is-signed-in read on every page, so it is not counted with sign-ins: 60 page views in 15 minutes made a signed-in visitor look signed out.-- app.use('/auth/', rateLimit({ windowMs: 15 * 60_000, limit: 60, skip: (req) => req.path === '/me', 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: 'services', service: 'services', host: 'openvibe.services', name: 'OpenVibe.Services', profile: 'ugc' })); }@@@ -208,6 +208,14 @@ function createSso({ config, keys, fetchImpl = globalThis.fetch, now = () => Datreturn res.json({ user: { username: v.username, display_name: v.displayName, subject_id: v.subject, role: v.role, avatar_url: v.avatarUrl || null, profile_color: v.profileColor || null } });});++ // The shared Dock needs a verified Network access token from this HTTP-only session.++ r.get('/navbar-token', (req, res) => {++ res.set('Cache-Control', cache.htmlHeaders({ private: true }));++ const viewer = req.viewer;++ if (!viewer || viewer.kind !== 'user' || !viewer.token) return res.status(401).json({ error: 'Not signed in' });++ return res.json({ token: viewer.token });++ });++r.get('/logout', (req, res, next) => {if (sameOriginRequest(req)) return next();res.set('Cache-Control', cache.htmlHeaders({ private: true }));@@@ -68,6 +68,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}', // filled from the current page (boost moves between pages)logoutUrl: '/auth/logout?next={path}', // Sign out in the shared navbar ends this site's session toonotificationsRealtime: true, // the bell hears new notifications over OpenVibe.Events (Shared 1.22.0)@@@ -60,6 +60,14 @@ const { signJwt } = require('./helpers/mocks');assert.strictEqual((await s.ctx.trust.get(APP)).tier, 'reviewed');});++ await check('the navbar receives a verified, uncached Network token only for a signed-in person', async () => {++ const nav = await s.get('/auth/navbar-token', { as: staff });++ assert.strictEqual(nav.status, 200);++ assert.match(JSON.parse(nav.text).token, /^[^.]+\.[^.]+\.[^.]+$/);++ assert.strictEqual(nav.headers.get('cache-control'), 'private, no-store');++ assert.strictEqual((await s.get('/auth/navbar-token')).status, 401);++ });++await check('another site cannot sign a person out; this site can', async () => {const cross = await s.get('/auth/logout', { as: staff, headers: { 'sec-fetch-site': 'cross-site' } });assert.strictEqual(cross.status, 200, 'a confirm page, not a sign-out');
@@ -90,6 +90,13 @@ server {
@@ -90,6 +90,13 @@ server {
proxy_pass http://127.0.0.1:4930;
proxy_pass http://127.0.0.1:4930;
}
}
+ # Give the Dock token the session probe's rate-limit budget.
+ location = /auth/navbar-token {
+ limit_req zone=ovservices_api burst=30 nodelay;
+ limit_req_status 429;
+ proxy_pass http://127.0.0.1:4930;
+ }
+
location /auth/ {
location /auth/ {
limit_req zone=ovservices_auth burst=10 nodelay;
limit_req zone=ovservices_auth burst=10 nodelay;
limit_req_status 429;
limit_req_status 429;
@@ -213,7 +213,7 @@ async function createApp(opts = {}) {
@@ -213,7 +213,7 @@ async function createApp(opts = {}) {
// ── Sign-in (OAuth2 + PKCE client of OpenVibe.Network) ──
// ── Sign-in (OAuth2 + PKCE client of OpenVibe.Network) ──
// /auth/me is the navbar's who-is-signed-in read on every page, so it is not counted with sign-ins: 60 page views in 15 minutes made a signed-in visitor look signed out.
// /auth/me is the navbar's who-is-signed-in read on every page, so it is not counted with sign-ins: 60 page views in 15 minutes made a signed-in visitor look signed out.
- app.use('/auth/', rateLimit({ windowMs: 15 * 60_000, limit: 60, skip: (req) => req.path === '/me', 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: 'services', service: 'services', host: 'openvibe.services', name: 'OpenVibe.Services', profile: 'ugc' })); }
{ const legal = require('openvibe-shared/legal'); app.get(legal.PATHS, legal.handler({ id: 'services', service: 'services', host: 'openvibe.services', name: 'OpenVibe.Services', profile: 'ugc' })); }
@@ -208,6 +208,14 @@ function createSso({ config, keys, fetchImpl = globalThis.fetch, now = () => Dat
@@ -208,6 +208,14 @@ function createSso({ config, keys, fetchImpl = globalThis.fetch, now = () => Dat
return res.json({ user: { username: v.username, display_name: v.displayName, subject_id: v.subject, role: v.role, avatar_url: v.avatarUrl || null, profile_color: v.profileColor || null } });
return res.json({ user: { username: v.username, display_name: v.displayName, subject_id: v.subject, role: v.role, avatar_url: v.avatarUrl || null, profile_color: v.profileColor || null } });
});
});
+ // The shared Dock needs a verified Network access token from this HTTP-only session.
+ r.get('/navbar-token', (req, res) => {
+ res.set('Cache-Control', cache.htmlHeaders({ private: true }));
+ const viewer = req.viewer;
+ if (!viewer || viewer.kind !== 'user' || !viewer.token) return res.status(401).json({ error: 'Not signed in' });
+ return res.json({ token: viewer.token });
+ });
+
r.get('/logout', (req, res, next) => {
r.get('/logout', (req, res, next) => {
if (sameOriginRequest(req)) return next();
if (sameOriginRequest(req)) return next();
res.set('Cache-Control', cache.htmlHeaders({ private: true }));
res.set('Cache-Control', cache.htmlHeaders({ private: true }));
@@ -68,6 +68,7 @@ function renderPage(o) {
@@ -68,6 +68,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}', // filled from the current page (boost moves between pages)
loginUrl: '/auth/login?next={path}', // filled from the current page (boost moves between pages)
logoutUrl: '/auth/logout?next={path}', // Sign out in the shared navbar ends this site's session too
logoutUrl: '/auth/logout?next={path}', // Sign out in the shared navbar ends this site's session too
notificationsRealtime: true, // the bell hears new notifications over OpenVibe.Events (Shared 1.22.0)
notificationsRealtime: true, // the bell hears new notifications over OpenVibe.Events (Shared 1.22.0)
@@ -60,6 +60,14 @@ const { signJwt } = require('./helpers/mocks');
@@ -60,6 +60,14 @@ const { signJwt } = require('./helpers/mocks');
assert.strictEqual((await s.ctx.trust.get(APP)).tier, 'reviewed');
assert.strictEqual((await s.ctx.trust.get(APP)).tier, 'reviewed');
});
});
+ await check('the navbar receives a verified, uncached Network token only for a signed-in person', async () => {
+ const nav = await s.get('/auth/navbar-token', { as: staff });
+ assert.strictEqual(nav.status, 200);
+ assert.match(JSON.parse(nav.text).token, /^[^.]+\.[^.]+\.[^.]+$/);
+ assert.strictEqual(nav.headers.get('cache-control'), 'private, no-store');
+ assert.strictEqual((await s.get('/auth/navbar-token')).status, 401);
+ });
+
await check('another site cannot sign a person out; this site can', async () => {
await check('another site cannot sign a person out; this site can', async () => {
const cross = await s.get('/auth/logout', { as: staff, headers: { 'sec-fetch-site': 'cross-site' } });
const cross = await s.get('/auth/logout', { as: staff, headers: { 'sec-fetch-site': 'cross-site' } });
assert.strictEqual(cross.status, 200, 'a confirm page, not a sign-out');
assert.strictEqual(cross.status, 200, 'a confirm page, not a sign-out');