@botfabrik/engine-webclient 4.101.3-alpha.0 → 4.101.3-alpha.2
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/auth/index.d.ts +1 -1
- package/dist/auth/index.js +14 -10
- package/dist/index.js +5 -1
- package/dist/requestSessionData.test.js +1 -1
- package/package.json +3 -3
package/dist/auth/index.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export type AuthenticatedUser = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare function setUpSamlAuth(bot: BotInstance, auth: Auth, clientName: string, nsp: Namespace): void;
|
|
10
10
|
export declare function storeLoginRequestToken(loginRequestToken: string, socketId: string): void;
|
|
11
|
-
export declare function verifyLoginToken(token: string | undefined, auth: Auth | undefined, logger: Logger): AuthenticatedUser | undefined
|
|
11
|
+
export declare function verifyLoginToken(token: string | undefined, auth: Auth | undefined, logger: Logger): Promise<AuthenticatedUser | undefined>;
|
package/dist/auth/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Strategy, } from '@node-saml/passport-saml';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import {
|
|
3
|
+
import { jwtVerify, SignJWT } from 'jose';
|
|
4
4
|
import passport from 'passport';
|
|
5
5
|
import { renderAuthErrorPage, renderAuthSuccessPage, setAuthPageHeaders, } from './auth-pages.js';
|
|
6
6
|
import { signRelayState, verifyRelayState } from './relay-state.js';
|
|
@@ -34,7 +34,7 @@ export function setUpSamlAuth(bot, auth, clientName, nsp) {
|
|
|
34
34
|
authenticateFn(req, res, next);
|
|
35
35
|
});
|
|
36
36
|
bot.webserver.express.post(callbackUrl, express.urlencoded({ extended: false }), (req, res, next) => {
|
|
37
|
-
const authenticatorFn = passport.authenticate(strategyName, { session: false }, (err, user) => {
|
|
37
|
+
const authenticatorFn = passport.authenticate(strategyName, { session: false }, async (err, user) => {
|
|
38
38
|
const lang = getLang(req);
|
|
39
39
|
setAuthPageHeaders(res);
|
|
40
40
|
try {
|
|
@@ -52,9 +52,11 @@ export function setUpSamlAuth(bot, auth, clientName, nsp) {
|
|
|
52
52
|
if (!user) {
|
|
53
53
|
return res.status(401).send(renderAuthErrorPage(lang));
|
|
54
54
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const secret = new TextEncoder().encode(auth.jwtSecret);
|
|
56
|
+
const loginToken = await new SignJWT(user)
|
|
57
|
+
.setProtectedHeader({ alg: 'HS256' })
|
|
58
|
+
.setExpirationTime('1m')
|
|
59
|
+
.sign(secret);
|
|
58
60
|
const socket = nsp.sockets.get(socketId);
|
|
59
61
|
if (socket) {
|
|
60
62
|
socket.emit('login-success', { loginToken });
|
|
@@ -89,14 +91,16 @@ function consumeLoginRequestToken(loginRequestToken) {
|
|
|
89
91
|
loginTokenCache.delete(loginRequestToken);
|
|
90
92
|
return { socketId: cachedLoginRequest.socketId };
|
|
91
93
|
}
|
|
92
|
-
export function verifyLoginToken(token, auth, logger) {
|
|
94
|
+
export async function verifyLoginToken(token, auth, logger) {
|
|
93
95
|
try {
|
|
94
96
|
if (auth) {
|
|
95
|
-
const
|
|
97
|
+
const secret = new TextEncoder().encode(auth.jwtSecret);
|
|
98
|
+
const { payload } = await jwtVerify(token ?? '', secret);
|
|
99
|
+
const p = payload;
|
|
96
100
|
return {
|
|
97
|
-
email:
|
|
98
|
-
firstName:
|
|
99
|
-
lastName:
|
|
101
|
+
email: p.email ?? '',
|
|
102
|
+
firstName: p.firstName,
|
|
103
|
+
lastName: p.lastName,
|
|
100
104
|
};
|
|
101
105
|
}
|
|
102
106
|
else {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Actions, ActionTypes, BotUser, TextMessage, } from '@botfabrik/engine-domain';
|
|
2
2
|
import { getPdf } from '@botfabrik/engine-transcript-export';
|
|
3
3
|
import { static as serveStatic } from 'express';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
4
6
|
import { setUpSamlAuth, storeLoginRequestToken, verifyLoginToken, } from './auth/index.js';
|
|
5
7
|
import { CLIENT_TYPE } from './constants.js';
|
|
6
8
|
import createSessionInfo from './createSessionInfo.js';
|
|
@@ -15,6 +17,8 @@ import { Devices, } from './types.js';
|
|
|
15
17
|
import { version } from './version.js';
|
|
16
18
|
import index from './views/index.js';
|
|
17
19
|
export * from './types.js';
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = dirname(__filename);
|
|
18
22
|
export default (clientName, environment, props) => async (bot) => {
|
|
19
23
|
const logger = bot.logger.child({ clientType: CLIENT_TYPE, clientName });
|
|
20
24
|
// serve transcript pdf
|
|
@@ -127,7 +131,7 @@ const onTerminateSession = (socket, bot) => async ({ sessionId, // passed if the
|
|
|
127
131
|
};
|
|
128
132
|
const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: sessionIdFromClient, userId: defaultUserId, querystrings, loginToken, }) => {
|
|
129
133
|
try {
|
|
130
|
-
const authenticatedUser = verifyLoginToken(loginToken, props.auth, logger);
|
|
134
|
+
const authenticatedUser = await verifyLoginToken(loginToken, props.auth, logger);
|
|
131
135
|
const locale = extractLocale(querystrings, socket.request.headers['accept-language']);
|
|
132
136
|
const sessionsCollection = bot.store.db.collection('sessions');
|
|
133
137
|
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await requestSessionData(sessionIdFromClient, querystrings, sessionsCollection, clientName, props);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botfabrik/engine-webclient",
|
|
3
|
-
"version": "4.101.3-alpha.
|
|
3
|
+
"version": "4.101.3-alpha.2",
|
|
4
4
|
"description": "Webclient for Botfabriks Bot Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"accept-language-parser": "^1.5.0",
|
|
40
40
|
"express": "^5.1.0",
|
|
41
41
|
"flat": "^6.0.1",
|
|
42
|
-
"
|
|
42
|
+
"jose": "^6.1.0",
|
|
43
43
|
"passport": "^0.7.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"tsx": "^4.20.6",
|
|
55
55
|
"typescript": "5.9.3"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "edfe65ffc53d2d999e47936b50a6f2d1258105c6"
|
|
58
58
|
}
|