@silexlabs/silex 3.0.0-alpha.183 → 3.0.0-alpha.185
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/client/css/admin.css +2 -1
- package/dist/client/css/admin.css.map +1 -1
- package/dist/client/js/main.js +1 -1
- package/dist/server/server/api/connectorApi.js +131 -13
- package/package.json +1 -1
- package/src/css/project-bar.scss +1 -1
- package/src/css/silex.scss +1 -0
- package/src/ts/server/api/connectorApi.ts +134 -15
|
@@ -144,12 +144,12 @@ async function routeLoginSuccess(req, res) {
|
|
|
144
144
|
...body,
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
res.send(getEndAuthHtml('Logged in', false, connectorId, connector.getOptions(body)));
|
|
147
|
+
res.send(getEndAuthHtml('Logged in', false, connectorId, type, connector.getOptions(body)));
|
|
148
148
|
}
|
|
149
149
|
catch (error) {
|
|
150
150
|
res
|
|
151
151
|
.status(validateStatus(error?.code ?? error?.httpStatusCode, 500))
|
|
152
|
-
.send(getEndAuthHtml(error.message, true));
|
|
152
|
+
.send(getEndAuthHtml(error.message, true, req.query.connectorId, req.query.type));
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
async function routeLogout(req, res) {
|
|
@@ -187,29 +187,147 @@ async function routeLogout(req, res) {
|
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
function getEndAuthHtml(message, error, connectorId, options) {
|
|
190
|
+
function getEndAuthHtml(message, error, connectorId, connectorType, options) {
|
|
191
191
|
const data = {
|
|
192
192
|
type: 'login',
|
|
193
193
|
error,
|
|
194
194
|
message,
|
|
195
195
|
connectorId,
|
|
196
|
+
connectorType,
|
|
196
197
|
options,
|
|
197
198
|
};
|
|
199
|
+
const status = error ? 'Error' : 'Success';
|
|
198
200
|
return `
|
|
199
|
-
|
|
201
|
+
<!DOCTYPE html><html lang="en">
|
|
200
202
|
<head>
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
<title>Authentication ${status}</title>
|
|
204
|
+
<style>
|
|
205
|
+
:root {
|
|
206
|
+
--primaryColor: #333333;
|
|
207
|
+
--secondaryColor: #ddd;
|
|
208
|
+
--tertiaryColor: #8873FE;
|
|
209
|
+
--quaternaryColor: #A291FF;
|
|
210
|
+
--darkerPrimaryColor: #292929;
|
|
211
|
+
--lighterPrimaryColor: #575757;
|
|
207
212
|
}
|
|
208
|
-
|
|
213
|
+
|
|
214
|
+
body {
|
|
215
|
+
font-family: Arial, sans-serif;
|
|
216
|
+
text-align: center;
|
|
217
|
+
margin: 50px;
|
|
218
|
+
color: var(--primaryColor);
|
|
219
|
+
background-color: var(--secondaryColor);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
h1 {
|
|
223
|
+
color: var(--tertiaryColor);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
p {
|
|
227
|
+
font-size: 18px;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
a {
|
|
231
|
+
color: var(--tertiaryColor);
|
|
232
|
+
text-decoration: none;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
a:hover {
|
|
236
|
+
text-decoration: underline;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.container {
|
|
240
|
+
max-width: 600px;
|
|
241
|
+
margin: auto;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.button {
|
|
245
|
+
display: inline-block;
|
|
246
|
+
margin-top: 20px;
|
|
247
|
+
padding: 10px 20px;
|
|
248
|
+
font-size: 16px;
|
|
249
|
+
color: var(--secondaryColor);
|
|
250
|
+
background-color: var(--tertiaryColor);
|
|
251
|
+
border: none;
|
|
252
|
+
border-radius: 5px;
|
|
253
|
+
text-decoration: none;
|
|
254
|
+
cursor: pointer;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.button:hover {
|
|
258
|
+
background-color: var(--quaternaryColor); /* Slightly lighter shade of tertiary color */
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.error {
|
|
262
|
+
display: none;
|
|
263
|
+
margin-top: 20px;
|
|
264
|
+
padding: 15px;
|
|
265
|
+
border: 1px solid var(--tertiaryColor);
|
|
266
|
+
border-radius: 5px;
|
|
267
|
+
text-wrap: wrap;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
</style>
|
|
209
271
|
</head>
|
|
210
272
|
<body>
|
|
211
|
-
<
|
|
212
|
-
|
|
273
|
+
<div class="container">
|
|
274
|
+
<div id="message">
|
|
275
|
+
<h1>Authentication ${status}</h1>
|
|
276
|
+
<p>${error ? '' : message}</p>
|
|
277
|
+
</div>
|
|
278
|
+
${error ? `
|
|
279
|
+
<p><a data-link-to href="/">click here to continue</a>.</p>
|
|
280
|
+
<a data-link-to href="/" class="button">Retry</a>
|
|
281
|
+
<pre id="error-container" class="error">${message}</pre>
|
|
282
|
+
<script>
|
|
283
|
+
document.getElementById('error-container').style.display = "block";
|
|
284
|
+
fetch("${constants_1.API_PATH}${constants_1.API_CONNECTOR_PATH}${constants_1.API_CONNECTOR_LOGOUT}?connectorId=${connectorId}&type=${connectorType}", {
|
|
285
|
+
method: 'POST',
|
|
286
|
+
headers: {
|
|
287
|
+
'Content-Type': 'application/json',
|
|
288
|
+
credentials: 'include', // sends the cookies with the request
|
|
289
|
+
},
|
|
290
|
+
})
|
|
291
|
+
if(window.opener && window.opener !== window) {
|
|
292
|
+
const linksTo = document.querySelectorAll('[data-link-to]');
|
|
293
|
+
linksTo.forEach(link => {
|
|
294
|
+
link.addEventListener('click', (e) => {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
const data = ${JSON.stringify(data)};
|
|
297
|
+
window.opener.postMessage(data, '*');
|
|
298
|
+
window.close();
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
</script>
|
|
303
|
+
` : `
|
|
304
|
+
<p>If this window doesn’t close automatically, <a href="/">click here to return to the homepage</a>.</p>
|
|
305
|
+
<a href="/" class="button">Go to Homepage</a>
|
|
306
|
+
<pre id="error-container" class="error"></pre>
|
|
307
|
+
<script>
|
|
308
|
+
const data = ${JSON.stringify(data)};
|
|
309
|
+
const errorContainer = document.getElementById('error-container');
|
|
310
|
+
const messageContainer = document.getElementById('message');
|
|
311
|
+
|
|
312
|
+
// Check if the window was opened programmatically and is valid
|
|
313
|
+
if (window.opener && window.opener !== window) {
|
|
314
|
+
try {
|
|
315
|
+
// Send a postMessage to the opener
|
|
316
|
+
window.opener.postMessage(data, '*');
|
|
317
|
+
// Attempt to close the window
|
|
318
|
+
window.close();
|
|
319
|
+
} catch (e) {
|
|
320
|
+
// Display error message if closing fails
|
|
321
|
+
errorContainer.innerText = "Unable to close the window. Please close it manually.";
|
|
322
|
+
errorContainer.style.display = "block";
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
messageContainer.innerHTML = '<h1>Redirecting, please wait...</h1>';
|
|
326
|
+
window.location.href = '/'
|
|
327
|
+
}
|
|
328
|
+
</script>
|
|
329
|
+
`}
|
|
330
|
+
</div>
|
|
213
331
|
</body>
|
|
214
332
|
</html>
|
|
215
333
|
`;
|
package/package.json
CHANGED
package/src/css/project-bar.scss
CHANGED
package/src/css/silex.scss
CHANGED
|
@@ -3,7 +3,7 @@ import { API_CONNECTOR_LIST, API_CONNECTOR_LOGIN_CALLBACK, API_CONNECTOR_USER, A
|
|
|
3
3
|
import { ServerConfig } from '../config'
|
|
4
4
|
import { requiredParam } from '../utils/validation'
|
|
5
5
|
import { Connector, getConnector, toConnectorData, toConnectorEnum } from '../connectors/connectors'
|
|
6
|
-
import { ApiConnectorListQuery, ApiConnectorListResponse, ApiConnectorLoggedInPostMessage, ApiConnectorLoginQuery, ApiConnectorUserQuery, ApiConnectorUserResponse, ApiConnectorLogoutQuery, ConnectorId, ApiConnectorLoginCbkQuery, ApiConnectorLoginCbkBody, ConnectorOptions, ApiResponseError } from '../../types'
|
|
6
|
+
import { ApiConnectorListQuery, ApiConnectorListResponse, ApiConnectorLoggedInPostMessage, ApiConnectorLoginQuery, ApiConnectorUserQuery, ApiConnectorUserResponse, ApiConnectorLogoutQuery, ConnectorId, ApiConnectorLoginCbkQuery, ApiConnectorLoginCbkBody, ConnectorOptions, ApiResponseError, ConnectorType } from '../../types'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @fileoverview The connector API adds routes to handle the connectors and the methods they implement, this includes authentication and user data.
|
|
@@ -263,11 +263,11 @@ async function routeLoginSuccess(req: Request, res: Response) {
|
|
|
263
263
|
})
|
|
264
264
|
}
|
|
265
265
|
// End the auth flow
|
|
266
|
-
res.send(getEndAuthHtml('Logged in', false, connectorId, connector.getOptions(body)))
|
|
266
|
+
res.send(getEndAuthHtml('Logged in', false, connectorId, type, connector.getOptions(body)))
|
|
267
267
|
} catch (error) {
|
|
268
268
|
res
|
|
269
269
|
.status(validateStatus(error?.code ?? error?.httpStatusCode, 500))
|
|
270
|
-
.send(getEndAuthHtml(error.message, true))
|
|
270
|
+
.send(getEndAuthHtml(error.message, true, req.query.connectorId as ConnectorId, req.query.type as ConnectorType))
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
|
|
@@ -314,31 +314,150 @@ async function routeLogout(req: Request, res: Response) {
|
|
|
314
314
|
* Utility function to send an HTML page to the browser
|
|
315
315
|
* is page will send a postMessage to the parent window and close itself
|
|
316
316
|
*/
|
|
317
|
-
function getEndAuthHtml(message: string, error: boolean, connectorId
|
|
317
|
+
function getEndAuthHtml(message: string, error: boolean, connectorId: ConnectorId, connectorType: ConnectorType, options?: ConnectorOptions): string {
|
|
318
318
|
// Data for postMessage
|
|
319
319
|
const data = {
|
|
320
320
|
type: 'login', // For postMessage
|
|
321
321
|
error,
|
|
322
322
|
message,
|
|
323
323
|
connectorId,
|
|
324
|
+
connectorType,
|
|
324
325
|
options,
|
|
325
326
|
} as ApiConnectorLoggedInPostMessage
|
|
326
|
-
//
|
|
327
|
+
// Determine status title and heading based on the error
|
|
328
|
+
const status = error ? 'Error' : 'Success'
|
|
329
|
+
// Return the HTML template
|
|
327
330
|
return `
|
|
328
|
-
|
|
331
|
+
<!DOCTYPE html><html lang="en">
|
|
329
332
|
<head>
|
|
330
|
-
<
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
333
|
+
<title>Authentication ${status}</title>
|
|
334
|
+
<style>
|
|
335
|
+
:root {
|
|
336
|
+
--primaryColor: #333333;
|
|
337
|
+
--secondaryColor: #ddd;
|
|
338
|
+
--tertiaryColor: #8873FE;
|
|
339
|
+
--quaternaryColor: #A291FF;
|
|
340
|
+
--darkerPrimaryColor: #292929;
|
|
341
|
+
--lighterPrimaryColor: #575757;
|
|
336
342
|
}
|
|
337
|
-
|
|
343
|
+
|
|
344
|
+
body {
|
|
345
|
+
font-family: Arial, sans-serif;
|
|
346
|
+
text-align: center;
|
|
347
|
+
margin: 50px;
|
|
348
|
+
color: var(--primaryColor);
|
|
349
|
+
background-color: var(--secondaryColor);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
h1 {
|
|
353
|
+
color: var(--tertiaryColor);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
p {
|
|
357
|
+
font-size: 18px;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
a {
|
|
361
|
+
color: var(--tertiaryColor);
|
|
362
|
+
text-decoration: none;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
a:hover {
|
|
366
|
+
text-decoration: underline;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.container {
|
|
370
|
+
max-width: 600px;
|
|
371
|
+
margin: auto;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.button {
|
|
375
|
+
display: inline-block;
|
|
376
|
+
margin-top: 20px;
|
|
377
|
+
padding: 10px 20px;
|
|
378
|
+
font-size: 16px;
|
|
379
|
+
color: var(--secondaryColor);
|
|
380
|
+
background-color: var(--tertiaryColor);
|
|
381
|
+
border: none;
|
|
382
|
+
border-radius: 5px;
|
|
383
|
+
text-decoration: none;
|
|
384
|
+
cursor: pointer;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.button:hover {
|
|
388
|
+
background-color: var(--quaternaryColor); /* Slightly lighter shade of tertiary color */
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.error {
|
|
392
|
+
display: none;
|
|
393
|
+
margin-top: 20px;
|
|
394
|
+
padding: 15px;
|
|
395
|
+
border: 1px solid var(--tertiaryColor);
|
|
396
|
+
border-radius: 5px;
|
|
397
|
+
text-wrap: wrap;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
</style>
|
|
338
401
|
</head>
|
|
339
402
|
<body>
|
|
340
|
-
<
|
|
341
|
-
|
|
403
|
+
<div class="container">
|
|
404
|
+
<div id="message">
|
|
405
|
+
<h1>Authentication ${status}</h1>
|
|
406
|
+
<p>${error ? '' : message}</p>
|
|
407
|
+
</div>
|
|
408
|
+
${ error ? `
|
|
409
|
+
<p><a data-link-to href="/">click here to continue</a>.</p>
|
|
410
|
+
<a data-link-to href="/" class="button">Retry</a>
|
|
411
|
+
<pre id="error-container" class="error">${message}</pre>
|
|
412
|
+
<script>
|
|
413
|
+
document.getElementById('error-container').style.display = "block";
|
|
414
|
+
fetch("${ API_PATH }${ API_CONNECTOR_PATH }${ API_CONNECTOR_LOGOUT }?connectorId=${ connectorId }&type=${ connectorType }", {
|
|
415
|
+
method: 'POST',
|
|
416
|
+
headers: {
|
|
417
|
+
'Content-Type': 'application/json',
|
|
418
|
+
credentials: 'include', // sends the cookies with the request
|
|
419
|
+
},
|
|
420
|
+
})
|
|
421
|
+
if(window.opener && window.opener !== window) {
|
|
422
|
+
const linksTo = document.querySelectorAll('[data-link-to]');
|
|
423
|
+
linksTo.forEach(link => {
|
|
424
|
+
link.addEventListener('click', (e) => {
|
|
425
|
+
e.preventDefault();
|
|
426
|
+
const data = ${JSON.stringify(data)};
|
|
427
|
+
window.opener.postMessage(data, '*');
|
|
428
|
+
window.close();
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
</script>
|
|
433
|
+
` : `
|
|
434
|
+
<p>If this window doesn’t close automatically, <a href="/">click here to return to the homepage</a>.</p>
|
|
435
|
+
<a href="/" class="button">Go to Homepage</a>
|
|
436
|
+
<pre id="error-container" class="error"></pre>
|
|
437
|
+
<script>
|
|
438
|
+
const data = ${JSON.stringify(data)};
|
|
439
|
+
const errorContainer = document.getElementById('error-container');
|
|
440
|
+
const messageContainer = document.getElementById('message');
|
|
441
|
+
|
|
442
|
+
// Check if the window was opened programmatically and is valid
|
|
443
|
+
if (window.opener && window.opener !== window) {
|
|
444
|
+
try {
|
|
445
|
+
// Send a postMessage to the opener
|
|
446
|
+
window.opener.postMessage(data, '*');
|
|
447
|
+
// Attempt to close the window
|
|
448
|
+
window.close();
|
|
449
|
+
} catch (e) {
|
|
450
|
+
// Display error message if closing fails
|
|
451
|
+
errorContainer.innerText = "Unable to close the window. Please close it manually.";
|
|
452
|
+
errorContainer.style.display = "block";
|
|
453
|
+
}
|
|
454
|
+
} else {
|
|
455
|
+
messageContainer.innerHTML = '<h1>Redirecting, please wait...</h1>';
|
|
456
|
+
window.location.href = '/'
|
|
457
|
+
}
|
|
458
|
+
</script>
|
|
459
|
+
`}
|
|
460
|
+
</div>
|
|
342
461
|
</body>
|
|
343
462
|
</html>
|
|
344
463
|
`
|