@oondemand/oon-core-back 0.4.17 → 0.4.18
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/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) => {
|