@heliyos/heliyos-api-core 1.0.22 → 1.0.23
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/dist/authentication.d.ts +4 -4
- package/dist/authentication.js +24 -24
- package/dist/authorization.d.ts +4 -4
- package/dist/authorization.js +5 -5
- package/package.json +1 -1
package/dist/authentication.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export declare const authentication: (req: Request, res: Response, next: NextFun
|
|
|
10
10
|
export interface IAuthResponseApiKey {
|
|
11
11
|
id: number;
|
|
12
12
|
name?: string;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
customerId?: string;
|
|
14
|
+
locationIds: string[] | undefined;
|
|
15
15
|
policy: IAuthResponseApiKeyPolicy[] | undefined;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
userId: string;
|
|
17
|
+
organizationId: string;
|
|
18
18
|
}
|
|
19
19
|
interface IAuthResponseApiKeyPolicy {
|
|
20
20
|
resource: string;
|
package/dist/authentication.js
CHANGED
|
@@ -41,8 +41,8 @@ const authentication = (req, res, next) => __awaiter(void 0, void 0, void 0, fun
|
|
|
41
41
|
auth_type: undefined,
|
|
42
42
|
},
|
|
43
43
|
output: {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
isBasicAuth: false,
|
|
45
|
+
isApiKeyAuth: false,
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
// Check for the type of authentication
|
|
@@ -51,7 +51,7 @@ const authentication = (req, res, next) => __awaiter(void 0, void 0, void 0, fun
|
|
|
51
51
|
// Either of BASIC / COOKIE / BEARER
|
|
52
52
|
const authenticationResponse = yield authenticate_request(container);
|
|
53
53
|
if (authenticationResponse) {
|
|
54
|
-
container.output.
|
|
54
|
+
container.output.loggedInUser = authenticationResponse;
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
return res.status(401).json({
|
|
@@ -173,9 +173,9 @@ const authenticate_request = (container) => __awaiter(void 0, void 0, void 0, fu
|
|
|
173
173
|
case "API_KEY":
|
|
174
174
|
// Call API authorization server with api key
|
|
175
175
|
result = yield verify_api_key(authentication_header.replace(/Bearer /, ""));
|
|
176
|
-
// Set
|
|
176
|
+
// Set isApiKeyAuth if there is a api key id
|
|
177
177
|
if (result === null || result === void 0 ? void 0 : result.id) {
|
|
178
|
-
container.output.
|
|
178
|
+
container.output.isApiKeyAuth = true;
|
|
179
179
|
}
|
|
180
180
|
break;
|
|
181
181
|
default:
|
|
@@ -203,8 +203,8 @@ const do_basic_auth = (container) => {
|
|
|
203
203
|
error.status = "401";
|
|
204
204
|
throw error;
|
|
205
205
|
}
|
|
206
|
-
// Set
|
|
207
|
-
container.output.
|
|
206
|
+
// Set isBasicAuth
|
|
207
|
+
container.output.isBasicAuth = true;
|
|
208
208
|
// An empty object is returned because returning a falsy
|
|
209
209
|
// object will means unauthorized.
|
|
210
210
|
return {};
|
|
@@ -216,29 +216,29 @@ const do_basic_auth = (container) => {
|
|
|
216
216
|
* @returns
|
|
217
217
|
*/
|
|
218
218
|
const set_logged_in_user = function (container, req) {
|
|
219
|
-
// If
|
|
220
|
-
const { output: {
|
|
221
|
-
if (
|
|
222
|
-
req.
|
|
219
|
+
// If isBasicAuth, set it and return
|
|
220
|
+
const { output: { isBasicAuth, isApiKeyAuth }, input: { auth_type }, } = container;
|
|
221
|
+
if (isBasicAuth) {
|
|
222
|
+
req.isBasicAuth = isBasicAuth;
|
|
223
223
|
return undefined;
|
|
224
224
|
}
|
|
225
|
-
// Set
|
|
226
|
-
if (
|
|
227
|
-
req.
|
|
228
|
-
const { output: {
|
|
225
|
+
// Set isApiKeyAuth
|
|
226
|
+
if (isApiKeyAuth) {
|
|
227
|
+
req.isApiKeyAuth = isApiKeyAuth;
|
|
228
|
+
const { output: { loggedInUser }, } = container;
|
|
229
229
|
// Modify req object with logged in user data
|
|
230
|
-
req.
|
|
230
|
+
req.loggedInUser = loggedInUser;
|
|
231
231
|
return undefined;
|
|
232
232
|
}
|
|
233
233
|
//
|
|
234
234
|
// Handle Cookie and Bearer token
|
|
235
|
-
const { output: {
|
|
236
|
-
const { token,
|
|
235
|
+
const { output: { loggedInUser }, } = container;
|
|
236
|
+
const { token, userId, organizationId } = loggedInUser;
|
|
237
237
|
// Modify req object with logged in user data
|
|
238
|
-
req.
|
|
238
|
+
req.loggedInUser = {
|
|
239
239
|
token,
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
userId,
|
|
241
|
+
organizationId,
|
|
242
242
|
auth_type,
|
|
243
243
|
};
|
|
244
244
|
return undefined;
|
|
@@ -256,12 +256,12 @@ const call_auth_api_server = (token) => __awaiter(void 0, void 0, void 0, functi
|
|
|
256
256
|
const auth_result = yield _1.axios.auth_server.post("/v1/auth/verify_token_v2", {
|
|
257
257
|
token: token,
|
|
258
258
|
});
|
|
259
|
-
if ((_b = (_a = auth_result.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.
|
|
259
|
+
if ((_b = (_a = auth_result.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.isValid) {
|
|
260
260
|
// Resolve request with received data
|
|
261
261
|
return {
|
|
262
262
|
token,
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
userId: auth_result.data.data.payload.userId,
|
|
264
|
+
organizationId: auth_result.data.data.payload.organizationId,
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
else {
|
package/dist/authorization.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authorize the user with the resource action
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
3
|
+
* @param organizationId
|
|
4
|
+
* @param userId
|
|
5
|
+
* @param resourceAction
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export declare const authorize_user: <T = string, U = string>(
|
|
8
|
+
export declare const authorize_user: <T = string, U = string>(organizationId: T, userId: U, resourceAction: string) => Promise<{
|
|
9
9
|
isAllowed: string;
|
|
10
10
|
userRole: string;
|
|
11
11
|
}>;
|
package/dist/authorization.js
CHANGED
|
@@ -14,15 +14,15 @@ const customError_1 = require("./@types/globals/customError");
|
|
|
14
14
|
const axios_1 = require("./axios");
|
|
15
15
|
/**
|
|
16
16
|
* Authorize the user with the resource action
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
17
|
+
* @param organizationId
|
|
18
|
+
* @param userId
|
|
19
|
+
* @param resourceAction
|
|
20
20
|
* @returns
|
|
21
21
|
*/
|
|
22
22
|
// eslint-disable-next-line import/prefer-default-export, @typescript-eslint/naming-convention
|
|
23
|
-
const authorize_user = (
|
|
23
|
+
const authorize_user = (organizationId, userId, resourceAction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
try {
|
|
25
|
-
const authenticationResponse = yield axios_1.core_axios.auth_server.post(`v1/auth/user/${
|
|
25
|
+
const authenticationResponse = yield axios_1.core_axios.auth_server.post(`v1/auth/user/${userId}`, { resourceAction, organizationId });
|
|
26
26
|
return authenticationResponse.data.data;
|
|
27
27
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
|
|
28
28
|
}
|