Technical User cannot login to the App
MODIFY
package-lock.json
package-lock.json
"emailjs": "^3.6.0",
"express": "^4.17.1",
"express-sanitizer": "^1.0.6",
+ "express-useragent": "^1.0.15",
"firebase-admin": "^10.0.0",
"helmet": "^4.6.0",
"hpp": "^0.2.3",
"@types/cors": "^2.8.10",
"@types/ejs": "^3.1.0",
"@types/express": "^4.17.13",
+ "@types/express-useragent": "^1.0.1",
"@types/faker": "^5.5.5",
"@types/hpp": "^0.2.2",
"@types/i18n-js": "^3.8.2",
"@types/express": "*"
}
},
+ "node_modules/@types/express-useragent": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/@types/express-useragent/-/express-useragent-1.0.1.tgz",
+ "integrity": "sha512-pu0riWrnDLf5b1A19jKE7vXnvog/43IDK0ITgieleXxxE6zyJhdnX+7ScfPcSp9rRIB/HDqqR7dQj5knpjwLaw==",
+ "dev": true,
+ "dependencies": {
+ "@types/express": "*"
+ }
+ },
"node_modules/@types/faker": {
"version": "5.5.9",
"resolved": "https://registry.npmjs.org/@types/faker/-/faker-5.5.9.tgz",
"node": "*"
}
},
+ "node_modules/express-useragent": {
+ "version": "1.0.15",
+ "resolved": "https://registry.npmjs.org/express-useragent/-/express-useragent-1.0.15.tgz",
+ "integrity": "sha512-eq5xMiYCYwFPoekffMjvEIk+NWdlQY9Y38OsTyl13IvA728vKT+q/CSERYWzcw93HGBJcIqMIsZC5CZGARPVdg==",
+ "engines": {
+ "node": ">=4.5"
+ }
+ },
"node_modules/express/node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"@types/express": "*"
}
},
+ "@types/express-useragent": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/@types/express-useragent/-/express-useragent-1.0.1.tgz",
+ "integrity": "sha512-pu0riWrnDLf5b1A19jKE7vXnvog/43IDK0ITgieleXxxE6zyJhdnX+7ScfPcSp9rRIB/HDqqR7dQj5knpjwLaw==",
+ "dev": true,
+ "requires": {
+ "@types/express": "*"
+ }
+ },
"@types/faker": {
"version": "5.5.9",
"resolved": "https://registry.npmjs.org/@types/faker/-/faker-5.5.9.tgz",
"sanitizer": "0.1.3"
}
},
+ "express-useragent": {
+ "version": "1.0.15",
+ "resolved": "https://registry.npmjs.org/express-useragent/-/express-useragent-1.0.15.tgz",
+ "integrity": "sha512-eq5xMiYCYwFPoekffMjvEIk+NWdlQY9Y38OsTyl13IvA728vKT+q/CSERYWzcw93HGBJcIqMIsZC5CZGARPVdg=="
+ },
"ext": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.6.0.tgz",

MODIFY
package.json
package.json
"xmake:download-libvibs-headers": "wget https://nexus.wdf.sap.corp:8443/nexus/service/local/repositories/3rd-party.releases.manual-uploads.hosted/content/lovell/sharp/libvips/8.10.6/libvips-8.10.6-linux-x64.tar.br -P ${WORKSPACE}/gen/tmp/libvips/v8.10.6/"
},
"dependencies": {
- "JSONStream": "^1.3.5",
"ajv": "^8.6.3",
"ajv-formats": "^2.1.1",
"ajv-keywords": "^5.0.0",
"emailjs": "^3.6.0",
"express": "^4.17.1",
"express-sanitizer": "^1.0.6",
+ "express-useragent": "^1.0.15",
"firebase-admin": "^10.0.0",
"helmet": "^4.6.0",
"hpp": "^0.2.3",
"i18n-js": "^3.8.0",
"intl": "^1.2.5",
"jimp": "^0.16.1",
+ "JSONStream": "^1.3.5",
"jsonwebtoken": "^8.5.1",
"locale": "^0.1.0",
"lodash": "^4.17.21",
"swagger-ui-express": "^4.1.6",
"tslib": "^2.2.0",
"tz-lookup": "^6.1.25",
- "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.3.0",
"urlencode": "^1.1.0",
"uuid": "^8.3.2",
+ "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.3.0",
"validator": "^13.7.0",
"ws": "^8.2.2"
},
"@types/cors": "^2.8.10",
"@types/ejs": "^3.1.0",
"@types/express": "^4.17.13",
+ "@types/express-useragent": "^1.0.1",
"@types/faker": "^5.5.5",
"@types/hpp": "^0.2.2",
"@types/i18n-js": "^3.8.2",

MODIFY
src/server/ExpressUtils.ts
src/server/ExpressUtils.ts
@@ -12,6 +12,7 @@ import helmet from 'helmet';
import hpp from 'hpp';
import locale from 'locale';
import morgan from 'morgan';
+import useragent from 'express-useragent';
bodyParserXml(bodyParser);
@@ -30,6 +31,7 @@ export default class ExpressUtils {
extended: false,
limit: bodyLimit
}));
+ app.use(useragent.express());
// Debug
if (debug || Utils.isDevelopmentEnv()) {
app.use(morgan((tokens, req: Request, res: Response) =>

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -820,6 +820,17 @@ export default class AuthService {
user: user
});
}
+ // Check Technical users
+ if (user.technical && AuthService.isLoggedFromUserDevice(req)) {
+ // No authorized to log
+ throw new AppError({
+ errorCode: HTTPError.TECHNICAL_USER_CANNOT_LOG_TO_UI_ERROR,
+ message: 'Technical user cannot log in to UI but only B2B',
+ module: MODULE_NAME,
+ method: 'checkUserLogin',
+ user: user
+ });
+ }
// Login OK
await AuthService.userLoginSucceeded(action, tenant, user, req, res, next);
} else {
@@ -827,4 +838,9 @@ export default class AuthService {
await AuthService.userLoginWrongPassword(action, tenant, user, req, res, next);
}
}
+
+ private static isLoggedFromUserDevice(req: Request) {
+ return req.useragent.isMobile ||
+ req.useragent.isDesktop;
+ }
}

MODIFY
src/types/HTTPError.ts
src/types/HTTPError.ts
@@ -38,6 +38,7 @@ export enum HTTPError {
USER_ACCOUNT_CHANGED = 595,
TENANT_COMPONENT_CHANGED = 596,
TENANT_ALREADY_EXIST = 597,
+ TECHNICAL_USER_CANNOT_LOG_TO_UI_ERROR = 598,
INVALID_CAPTCHA = 530,
INVALID_TOKEN_ERROR = 540,

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -244,14 +244,14 @@ export default class Logging {
// Keep date/time
req['timestamp'] = new Date();
// Check Tenant
- if (req['tenant']) {
- const tenant = req['tenant'] as Tenant;
+ if (req.tenant) {
+ const tenant = req.tenant;
tenantID = tenant.id;
tenantSubdomain = tenant.subdomain;
}
// Check User
- if (req['user']) {
- const user = req['user'] as User;
+ if (req.user) {
+ const user = req.user;
userID = user.id;
}
// Clear Default Tenant

MODIFY
types/express.d.ts
types/express.d.ts
-import Tenant from '../../src/types/Tenant';
-import UserToken from '../../src/types/UserToken';
+import { Details } from 'express-useragent';
+import Tenant from '../src/types/Tenant';
+import UserToken from '../src/types/UserToken';
declare module 'express' {
export interface Request {
locale: string;
user?: UserToken;
tenant?: Tenant;
+ useragent?: Details;
}
}

Technical User cannot login to the App