@bigid/apps-infrastructure-node-js 1.181.2 → 1.181.3
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/lib/utils/tokenUtil.d.ts +1 -1
- package/lib/utils/tokenUtil.js +18 -10
- package/package.json +1 -1
- package/src/utils/tokenUtil.ts +13 -7
package/lib/utils/tokenUtil.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const getAccessTokenFromRefreshToken: (refreshToken: string) => Promise<string>;
|
|
2
|
-
export declare const getTokenByUsernameAndPassword: () => Promise<
|
|
2
|
+
export declare const getTokenByUsernameAndPassword: (username?: string, password?: string) => Promise<string>;
|
|
3
3
|
export declare const getAuth0Token: () => Promise<string>;
|
|
4
4
|
export declare const tokenExchange: (auth0Token: string, tenantId?: string) => Promise<string>;
|
package/lib/utils/tokenUtil.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.tokenExchange = exports.getAuth0Token = exports.getTokenByUsernameAndPas
|
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const https_1 = require("https");
|
|
18
18
|
const services_1 = require("../services");
|
|
19
|
+
const appLogger_1 = require("./appLogger");
|
|
19
20
|
const auth0Payload = {
|
|
20
21
|
client_id: process.env.CLIENT_ID,
|
|
21
22
|
client_secret: process.env.CLIENT_SECRET,
|
|
@@ -33,21 +34,28 @@ const getAccessTokenFromRefreshToken = (refreshToken) => __awaiter(void 0, void
|
|
|
33
34
|
return accessToken;
|
|
34
35
|
});
|
|
35
36
|
exports.getAccessTokenFromRefreshToken = getAccessTokenFromRefreshToken;
|
|
36
|
-
const getTokenByUsernameAndPassword = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
const getTokenByUsernameAndPassword = (username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
var _a, _b, _c, _d, _e;
|
|
39
|
+
try {
|
|
40
|
+
const requestBody = {
|
|
41
|
+
username: username || process.env.USERNAME,
|
|
42
|
+
password: password || process.env.PASSWORD,
|
|
43
|
+
};
|
|
44
|
+
const res = yield (0, services_1.executePost)(services_1.RequestMethod.POST, process.env.BIGID_BASE_URL, requestBody);
|
|
45
|
+
return (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.auth_token) === null || _b === void 0 ? void 0 : _b.toString();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const errorMessage = (_e = (_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.toString();
|
|
49
|
+
(0, appLogger_1.logError)(errorMessage);
|
|
50
|
+
return errorMessage;
|
|
51
|
+
}
|
|
44
52
|
});
|
|
45
53
|
exports.getTokenByUsernameAndPassword = getTokenByUsernameAndPassword;
|
|
46
54
|
const getAuth0Token = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
var
|
|
55
|
+
var _f;
|
|
48
56
|
if (canUseLocalToken(auth0Token))
|
|
49
57
|
return auth0Token;
|
|
50
|
-
const auth0Domain = (
|
|
58
|
+
const auth0Domain = (_f = process.env.AUTH0_DOMAIN) === null || _f === void 0 ? void 0 : _f.replace(/\/$/, '');
|
|
51
59
|
const { data: { access_token }, } = yield axios_1.default.post(`${auth0Domain}/oauth/token`, auth0Payload);
|
|
52
60
|
auth0Token = access_token;
|
|
53
61
|
return access_token;
|
package/package.json
CHANGED
package/src/utils/tokenUtil.ts
CHANGED
|
@@ -28,13 +28,19 @@ export const getAccessTokenFromRefreshToken = async (refreshToken: string) => {
|
|
|
28
28
|
return accessToken;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const getTokenByUsernameAndPassword = async () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
export const getTokenByUsernameAndPassword = async (username?: string, password?: string): Promise<string> => {
|
|
32
|
+
try {
|
|
33
|
+
const requestBody = {
|
|
34
|
+
username: username || process.env.USERNAME,
|
|
35
|
+
password: password || process.env.PASSWORD,
|
|
36
|
+
};
|
|
37
|
+
const res = await executePost(RequestMethod.POST, process.env.BIGID_BASE_URL, requestBody);
|
|
38
|
+
return res.data?.auth_token?.toString();
|
|
39
|
+
} catch (error: any) {
|
|
40
|
+
const errorMessage = error.response?.data?.message?.toString();
|
|
41
|
+
logError(errorMessage);
|
|
42
|
+
return errorMessage;
|
|
43
|
+
}
|
|
38
44
|
};
|
|
39
45
|
|
|
40
46
|
export const getAuth0Token = async (): Promise<string> => {
|