Implement protected Studio catalog API and bounded public source reader
This commit is contained in:
+11
-5
@@ -49,7 +49,7 @@ function createWorkspaceResolver({ authMeUrl, clientMeUrl, fetchImpl = fetch, ti
|
||||
}
|
||||
const identity = await read(authUrl, { Authorization: 'Bearer ' + token, Accept: 'application/json' });
|
||||
const user = identity?.user;
|
||||
if (!user || typeof user.id !== 'string' || !user.id || user.isActive !== true) {
|
||||
if (!user || typeof user.id !== 'string' || !user.id || typeof user.email !== 'string' || !user.email || user.isActive !== true) {
|
||||
throw fail(401, 'INACTIVE_ACCOUNT', 'সক্রিয় Aura account প্রয়োজন।');
|
||||
}
|
||||
|
||||
@@ -66,15 +66,21 @@ function createWorkspaceResolver({ authMeUrl, clientMeUrl, fetchImpl = fetch, ti
|
||||
|
||||
// Client's existing gate owns membership/owner-switch decisions. Never trust a supplied client ID.
|
||||
const headers = { Cookie: 'aura_access=' + encodeURIComponent(token), Accept: 'application/json' };
|
||||
if (requested) headers['x-aura-tenant'] = requested;
|
||||
if (privileged && requested) headers['x-aura-tenant'] = requested;
|
||||
const context = await read(clientUrl, headers);
|
||||
if (context?.success !== true || typeof context.tenant !== 'string' || !context.tenant.trim() || context.tenant.length > 256) {
|
||||
if (context?.success !== true || typeof context.tenant !== 'string' || !context.tenant.trim() || context.tenant.length > 256 ||
|
||||
typeof context.clientId !== 'string' || !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(context.clientId)) {
|
||||
throw fail(403, 'WORKSPACE_UNAVAILABLE', 'আপনার workspace প্রস্তুত বা অনুমোদিত নয়।');
|
||||
}
|
||||
if (!context.actor || context.actor.id !== user.id || context.actor.role !== user.role ||
|
||||
typeof context.actor.email !== 'string' || context.actor.email.trim().toLowerCase() !== user.email.trim().toLowerCase()) {
|
||||
throw fail(401, 'SESSION_CHANGED', 'Account-এর তথ্য বদলেছে; আবার login করুন।');
|
||||
}
|
||||
const tenant = context.tenant.trim().toLowerCase();
|
||||
const clientId = context.clientId.toLowerCase();
|
||||
return {
|
||||
tenant,
|
||||
namespace: createHash('sha256').update(tenant).digest('hex'),
|
||||
tenant, clientId,
|
||||
namespace: createHash('sha256').update('client:' + clientId).digest('hex'),
|
||||
userId: user.id,
|
||||
role: context.role,
|
||||
canWriteProducts: context.perms?.products === true,
|
||||
|
||||
Reference in New Issue
Block a user