abler-api 0.1.47 → 0.1.49
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/cjs/pp-util.js +24 -10
- package/package.json +1 -1
package/dist/cjs/pp-util.js
CHANGED
|
@@ -50,7 +50,10 @@ class apiUtil$2 {
|
|
|
50
50
|
static testFlag = ppUtil$4.newGuid();
|
|
51
51
|
static envId_dev = "?";
|
|
52
52
|
static _validateBasicAuth = function (userName, password) {
|
|
53
|
-
throw
|
|
53
|
+
throw {
|
|
54
|
+
status: 500,
|
|
55
|
+
message: 'no basic auth validator'
|
|
56
|
+
};
|
|
54
57
|
}; // static apiCallRecSaver;
|
|
55
58
|
|
|
56
59
|
static config(appConfig, appErrCfg, appDbSql) {
|
|
@@ -1420,23 +1423,34 @@ class apiUtil$2 {
|
|
|
1420
1423
|
const authorization = getBasicAuthorization(req);
|
|
1421
1424
|
|
|
1422
1425
|
if (!authorization) {
|
|
1423
|
-
|
|
1424
|
-
|
|
1426
|
+
throw {
|
|
1427
|
+
status: 401,
|
|
1428
|
+
error: {
|
|
1429
|
+
code: 40101,
|
|
1430
|
+
message: 'need username and password'
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1425
1433
|
}
|
|
1426
1434
|
|
|
1427
|
-
if (!apiUtil$2._validateBasicAuth(authorization.name, authorization.pass)) {
|
|
1428
|
-
|
|
1429
|
-
|
|
1435
|
+
if (!(await apiUtil$2._validateBasicAuth(authorization.name, authorization.pass))) {
|
|
1436
|
+
throw {
|
|
1437
|
+
status: 401,
|
|
1438
|
+
error: {
|
|
1439
|
+
code: 40102,
|
|
1440
|
+
message: 'invalid username or password'
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1430
1443
|
}
|
|
1431
1444
|
} catch (e) {
|
|
1432
|
-
if (e.
|
|
1433
|
-
try {
|
|
1445
|
+
if (e.status === 401) {
|
|
1446
|
+
if (e.message) try {
|
|
1434
1447
|
res.set('WWW-Authenticate', `Basic realm=${e.message}`);
|
|
1435
|
-
return res.
|
|
1448
|
+
return res.status(401).send(e.message);
|
|
1436
1449
|
} catch {}
|
|
1450
|
+
res.set('WWW-Authenticate', `Basic realm=validate fail`);
|
|
1437
1451
|
}
|
|
1438
1452
|
|
|
1439
|
-
return res.
|
|
1453
|
+
return res.status(e.status || 500).send(e);
|
|
1440
1454
|
}
|
|
1441
1455
|
|
|
1442
1456
|
return next();
|