@oondemand/oon-core-back 0.4.17 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api/auth.routes.js +43 -1
- package/src/manifest/appManifest.js +14 -1
package/package.json
CHANGED
package/src/api/auth.routes.js
CHANGED
|
@@ -4,7 +4,7 @@ const auth = require("../core/middlewares/auth");
|
|
|
4
4
|
const ctx = require("../core/context");
|
|
5
5
|
const GenericError = require("../core/errors/GenericError");
|
|
6
6
|
const { asyncHandler, sendResponse } = require("../core/utils/helpers");
|
|
7
|
-
const { ensureInstance } = require("../core/utils/instanceActivation");
|
|
7
|
+
const { ensureInstance, operationalRequestHeaders } = require("../core/utils/instanceActivation");
|
|
8
8
|
const { findAccessForUser, audit } = require("../core/rbac/storage");
|
|
9
9
|
const { changeFirstAccessPassword } = require("../core/rbac/identityProvider");
|
|
10
10
|
const {
|
|
@@ -16,6 +16,8 @@ const {
|
|
|
16
16
|
|
|
17
17
|
const DEV_ACTIVATION_PATH = "/integracao/dev-local/ativar-central";
|
|
18
18
|
const TENANT_HEADER = "x-oon-tenant-id";
|
|
19
|
+
const SESSION_SCOPE_HEADER = "x-oon-session-scope";
|
|
20
|
+
const LAUNCH_EXCHANGE_PATH = "/integracao/app-access/launch/exchange";
|
|
19
21
|
const router = express.Router();
|
|
20
22
|
|
|
21
23
|
function readBasicAuthorization(req) {
|
|
@@ -50,6 +52,11 @@ function translateProviderError(error) {
|
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
function configuredSessionScope() {
|
|
56
|
+
const value = String(ctx.config.auth?.sessionScope || "").trim().toLowerCase();
|
|
57
|
+
return value === "ecosystem" ? value : undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
function tenantForLogin(req, instance) {
|
|
54
61
|
const tenancyModel =
|
|
55
62
|
ctx.config.tenancyModel || ctx.config.ecosystem?.tenancyModel;
|
|
@@ -95,6 +102,7 @@ router.post(
|
|
|
95
102
|
Authorization: authorization,
|
|
96
103
|
"Content-Type": "application/json",
|
|
97
104
|
"x-app-code": appCode,
|
|
105
|
+
...(configuredSessionScope() ? { [SESSION_SCOPE_HEADER]: configuredSessionScope() } : {}),
|
|
98
106
|
...(tenantId ? { [TENANT_HEADER]: tenantId } : {}),
|
|
99
107
|
},
|
|
100
108
|
},
|
|
@@ -107,6 +115,40 @@ router.post(
|
|
|
107
115
|
}),
|
|
108
116
|
);
|
|
109
117
|
|
|
118
|
+
router.post(
|
|
119
|
+
"/launch/exchange",
|
|
120
|
+
asyncHandler(async (req, res) => {
|
|
121
|
+
const code = String(req.body?.code || "").trim();
|
|
122
|
+
if (code.length < 32 || code.length > 512) {
|
|
123
|
+
throw new GenericError("Código de abertura inválido.", {
|
|
124
|
+
statusCode: 400,
|
|
125
|
+
code: "APP_LAUNCH_CODE_INVALID",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const baseUrl = getBaseUrl(req);
|
|
129
|
+
try {
|
|
130
|
+
const correlationId = String(req.headers["x-correlation-id"] || req.id || "");
|
|
131
|
+
const headers = await operationalRequestHeaders({ correlationId });
|
|
132
|
+
const response = await axios.post(
|
|
133
|
+
`${baseUrl}${LAUNCH_EXCHANGE_PATH}`,
|
|
134
|
+
{ code },
|
|
135
|
+
{
|
|
136
|
+
timeout: getTimeout(),
|
|
137
|
+
maxRedirects: 0,
|
|
138
|
+
headers: {
|
|
139
|
+
...headers,
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
res.set("Cache-Control", "no-store");
|
|
145
|
+
res.status(response.status).json(response.data);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw translateProviderError(error);
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
|
|
110
152
|
router.post(
|
|
111
153
|
"/ativar-dev-local",
|
|
112
154
|
asyncHandler(async (req, res) => {
|
|
@@ -220,7 +220,7 @@ function validateAppManifest(input, { coreVersion = corePackage.version } = {})
|
|
|
220
220
|
const allowedTopLevel = new Set([
|
|
221
221
|
"$schema", "schemaVersion", "id", "name", "slug", "appKind",
|
|
222
222
|
"tenancyModel", "availability", "accessMode", "authorizationMode", "accessPolicy", "deploymentMode",
|
|
223
|
-
"modules", "capabilities", "capabilitySettings", "compatibility", "activation", "rbac",
|
|
223
|
+
"modules", "capabilities", "capabilitySettings", "compatibility", "activation", "auth", "rbac",
|
|
224
224
|
]);
|
|
225
225
|
for (const key of Object.keys(input)) {
|
|
226
226
|
if (!allowedTopLevel.has(key)) addIssue(issues, key, "propriedade não suportada.");
|
|
@@ -286,6 +286,18 @@ function validateAppManifest(input, { coreVersion = corePackage.version } = {})
|
|
|
286
286
|
validateCapabilitySettings(input.capabilitySettings, input.capabilities, issues);
|
|
287
287
|
validateCompatibility(input.compatibility, issues, coreVersion);
|
|
288
288
|
validateActivation(input.activation, issues);
|
|
289
|
+
if (input.auth !== undefined) {
|
|
290
|
+
if (!isPlainObject(input.auth)) {
|
|
291
|
+
addIssue(issues, "auth", "deve ser um objeto.");
|
|
292
|
+
} else {
|
|
293
|
+
for (const key of Object.keys(input.auth)) {
|
|
294
|
+
if (key !== "sessionScope") addIssue(issues, `auth.${key}`, "propriedade não suportada.");
|
|
295
|
+
}
|
|
296
|
+
if (input.auth.sessionScope !== undefined && input.auth.sessionScope !== "ecosystem") {
|
|
297
|
+
addIssue(issues, "auth.sessionScope", "deve ser ecosystem.");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
289
301
|
validateRbac(input.rbac, issues);
|
|
290
302
|
if (issues.length) throw new AppManifestError("central.app.json inválido.", issues);
|
|
291
303
|
return JSON.parse(JSON.stringify(input));
|
|
@@ -320,6 +332,7 @@ function appManifestToConfig(manifest, manifestPath) {
|
|
|
320
332
|
modules: { ...manifest.modules },
|
|
321
333
|
capabilities: [...manifest.capabilities],
|
|
322
334
|
capabilitySettings: JSON.parse(JSON.stringify(manifest.capabilitySettings || {})),
|
|
335
|
+
auth: manifest.auth ? JSON.parse(JSON.stringify(manifest.auth)) : undefined,
|
|
323
336
|
rbac: manifest.rbac ? JSON.parse(JSON.stringify(manifest.rbac)) : undefined,
|
|
324
337
|
appManifest: manifest,
|
|
325
338
|
appManifestPath: manifestPath,
|