@crowdin/app-project-module 0.60.2 → 0.60.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.
|
@@ -19,52 +19,51 @@ const logger_1 = require("../../../util/logger");
|
|
|
19
19
|
const storage_1 = require("../../../storage");
|
|
20
20
|
function handle(config, integration) {
|
|
21
21
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
23
23
|
const message = {
|
|
24
24
|
uid: 'oauth_popup',
|
|
25
25
|
};
|
|
26
26
|
const code = req.query[((_b = (_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.fieldsMapping) === null || _b === void 0 ? void 0 : _b.code) || 'code'];
|
|
27
|
-
const state = ((_c = integration.oauthLogin) === null || _c === void 0 ? void 0 : _c.
|
|
28
|
-
? req.query[((_e = (_d = integration.oauthLogin) === null || _d === void 0 ? void 0 : _d.fieldsMapping) === null || _e === void 0 ? void 0 : _e.state) || 'state']
|
|
29
|
-
: undefined;
|
|
27
|
+
const state = req.query[((_d = (_c = integration.oauthLogin) === null || _c === void 0 ? void 0 : _c.fieldsMapping) === null || _d === void 0 ? void 0 : _d.state) || 'state'];
|
|
30
28
|
(0, logger_1.log)(`Received request from OAuth login callback. Code ${code}`);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
29
|
+
(0, logger_1.log)(`Received request from OAuth login callback. State ${state}`);
|
|
30
|
+
const clientId = Buffer.from(state, 'base64').toString();
|
|
31
|
+
const redirectUri = `${config.baseUrl}${(0, defaults_1.getOauthRoute)(integration)}`;
|
|
34
32
|
try {
|
|
35
33
|
const oauthLogin = integration.oauthLogin;
|
|
36
34
|
let credentials;
|
|
37
35
|
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.performGetTokenRequest) {
|
|
38
36
|
(0, logger_1.log)('Performing custom get bearer token request');
|
|
39
|
-
|
|
37
|
+
const loginForm = yield (0, storage_1.getStorage)().getMetadata((0, defaults_1.getOAuthLoginFormId)(clientId));
|
|
38
|
+
credentials = yield oauthLogin.performGetTokenRequest(code, req.query, req.originalUrl, redirectUri, loginForm);
|
|
40
39
|
}
|
|
41
40
|
else {
|
|
42
41
|
const request = {};
|
|
43
42
|
const oauthLogin = integration.oauthLogin;
|
|
44
|
-
request[((
|
|
45
|
-
request[((
|
|
46
|
-
request[((
|
|
47
|
-
request[((
|
|
43
|
+
request[((_e = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _e === void 0 ? void 0 : _e.code) || 'code'] = code;
|
|
44
|
+
request[((_f = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _f === void 0 ? void 0 : _f.clientId) || 'client_id'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientId;
|
|
45
|
+
request[((_g = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _g === void 0 ? void 0 : _g.clientSecret) || 'client_secret'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientSecret;
|
|
46
|
+
request[((_h = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _h === void 0 ? void 0 : _h.redirectUri) || 'redirect_uri'] = redirectUri;
|
|
48
47
|
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraAccessTokenParameters) {
|
|
49
48
|
Object.entries(oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraAccessTokenParameters).forEach(([key, value]) => (request[key] = value));
|
|
50
49
|
}
|
|
51
|
-
credentials = (yield axios_1.default.post(((
|
|
50
|
+
credentials = (yield axios_1.default.post(((_j = integration.oauthLogin) === null || _j === void 0 ? void 0 : _j.accessTokenUrl) || '', request, {
|
|
52
51
|
headers: { Accept: 'application/json' },
|
|
53
52
|
})).data;
|
|
54
53
|
}
|
|
55
54
|
const oauthCredentials = { originalUrl: req.originalUrl };
|
|
56
|
-
oauthCredentials.accessToken = credentials[((
|
|
55
|
+
oauthCredentials.accessToken = credentials[((_k = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _k === void 0 ? void 0 : _k.accessToken) || 'access_token'];
|
|
57
56
|
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.refresh) {
|
|
58
|
-
oauthCredentials.refreshToken = credentials[((
|
|
57
|
+
oauthCredentials.refreshToken = credentials[((_l = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _l === void 0 ? void 0 : _l.refreshToken) || 'refresh_token'];
|
|
59
58
|
oauthCredentials.expireIn =
|
|
60
|
-
Number(credentials[((
|
|
59
|
+
Number(credentials[((_m = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _m === void 0 ? void 0 : _m.expiresIn) || 'expires_in']) + Date.now() / 1000;
|
|
61
60
|
}
|
|
62
61
|
message.data = oauthCredentials;
|
|
63
|
-
if (((
|
|
64
|
-
yield (0, storage_1.getStorage)().deleteMetadata(
|
|
65
|
-
yield (0, storage_1.getStorage)().saveMetadata(
|
|
62
|
+
if (((_o = integration.oauthLogin) === null || _o === void 0 ? void 0 : _o.mode) === 'polling') {
|
|
63
|
+
yield (0, storage_1.getStorage)().deleteMetadata((0, defaults_1.getOAuthPollingId)(clientId));
|
|
64
|
+
yield (0, storage_1.getStorage)().saveMetadata((0, defaults_1.getOAuthPollingId)(clientId), oauthCredentials);
|
|
66
65
|
}
|
|
67
|
-
return res.render('oauth', { message: JSON.stringify(message), oauthMode: (
|
|
66
|
+
return res.render('oauth', { message: JSON.stringify(message), oauthMode: (_p = integration.oauthLogin) === null || _p === void 0 ? void 0 : _p.mode });
|
|
68
67
|
}
|
|
69
68
|
catch (e) {
|
|
70
69
|
(0, logger_1.logError)(e);
|
|
@@ -233,7 +233,7 @@ export interface OAuthLogin {
|
|
|
233
233
|
*/
|
|
234
234
|
expiresIn?: string;
|
|
235
235
|
/**
|
|
236
|
-
* default 'state'
|
|
236
|
+
* default 'state'
|
|
237
237
|
*/
|
|
238
238
|
state?: string;
|
|
239
239
|
};
|
|
@@ -264,7 +264,7 @@ export interface OAuthLogin {
|
|
|
264
264
|
*/
|
|
265
265
|
performGetTokenRequest?: (code: string, query: {
|
|
266
266
|
[key: string]: any;
|
|
267
|
-
}, url: string, loginForm?: any) => Promise<any>;
|
|
267
|
+
}, url: string, redirectUri: string, loginForm?: any) => Promise<any>;
|
|
268
268
|
/**
|
|
269
269
|
* Override to implement request for refreshing token (only if 'refresh' is enabled)
|
|
270
270
|
*/
|
|
@@ -268,9 +268,7 @@ function constructOauthUrl({ config, integration, clientId, loginForm, }) {
|
|
|
268
268
|
return;
|
|
269
269
|
}
|
|
270
270
|
let url = oauth.getAuthorizationUrl(`${config.baseUrl}${getOauthRoute(integration)}`, loginForm);
|
|
271
|
-
|
|
272
|
-
url += `&${((_a = oauth.fieldsMapping) === null || _a === void 0 ? void 0 : _a.state) || 'state'}=${getOAuthPollingId(clientId)}`;
|
|
273
|
-
}
|
|
271
|
+
url += `&${((_a = oauth.fieldsMapping) === null || _a === void 0 ? void 0 : _a.state) || 'state'}=${Buffer.from(clientId).toString('base64')}`;
|
|
274
272
|
return url;
|
|
275
273
|
}
|
|
276
274
|
if (!oauth.authorizationUrl) {
|
|
@@ -279,11 +277,9 @@ function constructOauthUrl({ config, integration, clientId, loginForm, }) {
|
|
|
279
277
|
let url = oauth.authorizationUrl || '';
|
|
280
278
|
url += `?${((_b = oauth.fieldsMapping) === null || _b === void 0 ? void 0 : _b.clientId) || 'client_id'}=${oauth.clientId}`;
|
|
281
279
|
url += `&${((_c = oauth.fieldsMapping) === null || _c === void 0 ? void 0 : _c.redirectUri) || 'redirect_uri'}=${config.baseUrl}${getOauthRoute(integration)}`;
|
|
280
|
+
url += `&${((_d = oauth.fieldsMapping) === null || _d === void 0 ? void 0 : _d.state) || 'state'}=${Buffer.from(clientId).toString('base64')}`;
|
|
282
281
|
if (oauth.scope) {
|
|
283
|
-
url += `&${((
|
|
284
|
-
}
|
|
285
|
-
if (oauth.mode === 'polling') {
|
|
286
|
-
url += `&${((_e = oauth.fieldsMapping) === null || _e === void 0 ? void 0 : _e.state) || 'state'}=${getOAuthPollingId(clientId)}`;
|
|
282
|
+
url += `&${((_e = oauth.fieldsMapping) === null || _e === void 0 ? void 0 : _e.scope) || 'scope'}=${oauth.scope}`;
|
|
287
283
|
}
|
|
288
284
|
if (oauth.extraAutorizationUrlParameters) {
|
|
289
285
|
Object.entries(oauth.extraAutorizationUrlParameters).forEach(([key, value]) => (url += `&${key}=${value}`));
|
package/package.json
CHANGED