mbkauthe 4.9.0 → 5.0.0
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/docs/api.md +29 -178
- package/docs/db.md +1 -1
- package/docs/db.sql +305 -253
- package/index.js +5 -3
- package/lib/config/cookies.js +84 -18
- package/lib/config/index.js +3 -1
- package/lib/config/tokenScopes.js +1 -1
- package/lib/createTable.js +95 -8
- package/lib/db/AuthRepository.js +57 -16
- package/lib/db/BaseRepository.js +9 -1
- package/lib/db/dialects/postgres.js +1 -1
- package/lib/main.js +5 -5
- package/lib/middleware/auth.js +201 -218
- package/lib/middleware/index.js +13 -14
- package/lib/middleware/scopeValidator.js +8 -3
- package/lib/pool.js +5 -6
- package/lib/routes/auth.js +42 -47
- package/lib/routes/dbLogs.js +247 -29
- package/lib/routes/misc.js +6 -4
- package/lib/routes/oauth.js +19 -23
- package/lib/utils/dbQueryLogger.js +485 -80
- package/lib/utils/errors.js +1 -1
- package/lib/utils/logger.js +12 -0
- package/lib/utils/timingSafeToken.js +1 -1
- package/package.json +1 -1
- package/public/main.css +1 -1
- package/test.spec.js +515 -48
- package/views/pages/dbLogs.handlebars +618 -420
package/docs/api.md
CHANGED
|
@@ -291,6 +291,26 @@ Returns recent DB query diagnostics.
|
|
|
291
291
|
|
|
292
292
|
---
|
|
293
293
|
|
|
294
|
+
#### `POST /mbkauthe/db/reset`
|
|
295
|
+
|
|
296
|
+
Resets the DB query log and counters (dev-only).
|
|
297
|
+
|
|
298
|
+
**Authentication / Access:** Dev-only (mounted when `process.env.env === 'dev'` and `dbLogs=true`).
|
|
299
|
+
|
|
300
|
+
**Request Body:** None required.
|
|
301
|
+
|
|
302
|
+
**Success Response (200 OK):**
|
|
303
|
+
```json
|
|
304
|
+
{
|
|
305
|
+
"success": true,
|
|
306
|
+
"message": "Query log and count have been reset."
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Behavior:** Clears the in-memory or persisted DB query counters and logs used by the diagnostic UI. Returns `403` when DB logs are disabled.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
294
314
|
#### `GET /mbkauthe/validate-superadmin`
|
|
295
315
|
|
|
296
316
|
Validates that the current session has `SuperAdmin` role and returns a JSON summary.
|
|
@@ -328,6 +348,7 @@ The endpoints below are active in the router but are not fully expanded above. U
|
|
|
328
348
|
- `GET /mbkauthe/info.json` and `GET /mbkauthe/i.json` - Info page JSON.
|
|
329
349
|
- `GET /mbkauthe/ErrorCode` - Error codes page.
|
|
330
350
|
- `GET /mbkauthe/user/profilepic` - User profile picture proxy.
|
|
351
|
+
- `GET /mbkauthe/` - Mount root; renders the test/home page (alias of `/mbkauthe/test`).
|
|
331
352
|
|
|
332
353
|
**Admin:**
|
|
333
354
|
|
|
@@ -339,6 +360,12 @@ The endpoints below are active in the router but are not fully expanded above. U
|
|
|
339
360
|
- `GET /mbkauthe/main.css`
|
|
340
361
|
- `GET /mbkauthe/bg.webp`
|
|
341
362
|
|
|
363
|
+
Also served at the root level (outside `/mbkauthe`) are site icons:
|
|
364
|
+
|
|
365
|
+
- `GET /icon.svg` - Main application SVG icon (root-level)
|
|
366
|
+
- `GET /favicon.ico` - Fallback favicon (root-level)
|
|
367
|
+
- `GET /icon.png` - Additional icon size (root-level)
|
|
368
|
+
|
|
342
369
|
---
|
|
343
370
|
|
|
344
371
|
#### `POST /mbkauthe/api/login`
|
|
@@ -671,184 +698,6 @@ fetch('/mbkauthe/api/logout', {
|
|
|
671
698
|
|
|
672
699
|
### Multi-Account Endpoints
|
|
673
700
|
|
|
674
|
-
---
|
|
675
|
-
|
|
676
|
-
#### Token Management Endpoints
|
|
677
|
-
|
|
678
|
-
##### `POST /mbkauthe/api/token`
|
|
679
|
-
|
|
680
|
-
Create a new API token for the authenticated user.
|
|
681
|
-
|
|
682
|
-
**Rate Limit:** 10 requests per minute
|
|
683
|
-
|
|
684
|
-
**Authentication:** Session required (cookie or Bearer token)
|
|
685
|
-
|
|
686
|
-
**Request Body:**
|
|
687
|
-
```json
|
|
688
|
-
{
|
|
689
|
-
"name": "string (required, 1-255 chars, friendly name for the token)",
|
|
690
|
-
"expiresDays": "number (optional, 1-365, default 90)",
|
|
691
|
-
"scope": "string (optional, 'read-only' or 'write', default 'read-only')",
|
|
692
|
-
"allowedApps": "array (optional, app names or ['*'] for all apps)"
|
|
693
|
-
}
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
**Token Scopes:**
|
|
697
|
-
- `read-only`: Allows only read operations (GET, HEAD, OPTIONS methods)
|
|
698
|
-
- `write`: Allows all operations (GET, POST, PUT, DELETE, PATCH, etc.)
|
|
699
|
-
|
|
700
|
-
**Token Application Access:**
|
|
701
|
-
- Omit `allowedApps`: Token inherits from user's allowed apps
|
|
702
|
-
- `["app1", "app2"]`: Token restricted to specific apps (must be subset of user's apps for non-SuperAdmin)
|
|
703
|
-
- `["*"]`: All user's apps (non-SuperAdmin) or all system apps (SuperAdmin only)
|
|
704
|
-
- **SuperAdmin bypass**: SuperAdmin tokens work on any app regardless of `allowedApps` configuration
|
|
705
|
-
|
|
706
|
-
**Success Response (201 Created):**
|
|
707
|
-
```json
|
|
708
|
-
{
|
|
709
|
-
"success": true,
|
|
710
|
-
"token": "mbk_7f83a92b1dc4e5a6f89b012c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e",
|
|
711
|
-
"tokenId": 42,
|
|
712
|
-
"prefix": "mbk_7f83a92",
|
|
713
|
-
"name": "My API Token",
|
|
714
|
-
"scope": "read-only",
|
|
715
|
-
"allowedApps": ["App1", "App2"],
|
|
716
|
-
"expiresAt": "2025-04-27T12:34:56.000Z",
|
|
717
|
-
"createdAt": "2025-01-27T12:34:56.000Z",
|
|
718
|
-
"message": "Token created successfully. Save it now - it won't be shown again."
|
|
719
|
-
}
|
|
720
|
-
```
|
|
721
|
-
|
|
722
|
-
**Error Responses:**
|
|
723
|
-
|
|
724
|
-
| Status Code | Error Code | Message |
|
|
725
|
-
|------------|------------|---------|
|
|
726
|
-
| 400 | MISSING_REQUIRED_FIELD | Token name is required (1-255 characters) |
|
|
727
|
-
| 400 | MISSING_REQUIRED_FIELD | expiresDays must be between 1 and 365 |
|
|
728
|
-
| 400 | MISSING_REQUIRED_FIELD | Invalid scope. Available scopes: read-only, write |
|
|
729
|
-
| 400 | MISSING_REQUIRED_FIELD | allowedApps must be an array |
|
|
730
|
-
| 401 | SESSION_NOT_FOUND | Not authenticated |
|
|
731
|
-
| 403 | INSUFFICIENT_PERMISSIONS | Only SuperAdmin can create tokens with '*' (all apps) access |
|
|
732
|
-
| 403 | INSUFFICIENT_PERMISSIONS | You don't have access to app 'X' |
|
|
733
|
-
| 500 | INTERNAL_SERVER_ERROR | Internal Server Error |
|
|
734
|
-
|
|
735
|
-
**Example Requests:**
|
|
736
|
-
|
|
737
|
-
*Create a read-only token for specific apps:*
|
|
738
|
-
```javascript
|
|
739
|
-
const response = await fetch('/mbkauthe/api/token', {
|
|
740
|
-
method: 'POST',
|
|
741
|
-
headers: {
|
|
742
|
-
'Content-Type': 'application/json',
|
|
743
|
-
'Authorization': 'Bearer mbk_existing_token...' // or use session cookie
|
|
744
|
-
},
|
|
745
|
-
body: JSON.stringify({
|
|
746
|
-
name: 'CI/CD Pipeline Token',
|
|
747
|
-
expiresDays: 30,
|
|
748
|
-
scope: 'read-only',
|
|
749
|
-
allowedApps: ['App1', 'App2']
|
|
750
|
-
})
|
|
751
|
-
});
|
|
752
|
-
```
|
|
753
|
-
|
|
754
|
-
*Create a write token with inherited app access:*
|
|
755
|
-
```javascript
|
|
756
|
-
const response = await fetch('/mbkauthe/api/token', {
|
|
757
|
-
method: 'POST',
|
|
758
|
-
headers: { 'Content-Type': 'application/json' },
|
|
759
|
-
body: JSON.stringify({
|
|
760
|
-
name: 'Admin API Token',
|
|
761
|
-
scope: 'write'
|
|
762
|
-
// allowedApps omitted - inherits from user
|
|
763
|
-
})
|
|
764
|
-
});
|
|
765
|
-
```
|
|
766
|
-
|
|
767
|
-
---
|
|
768
|
-
|
|
769
|
-
##### `GET /mbkauthe/api/tokens`
|
|
770
|
-
|
|
771
|
-
List all API tokens for the authenticated user (token value not included).
|
|
772
|
-
|
|
773
|
-
**Rate Limit:** 10 requests per minute
|
|
774
|
-
|
|
775
|
-
**Authentication:** Session required (cookie or Bearer token)
|
|
776
|
-
|
|
777
|
-
**Success Response (200 OK):**
|
|
778
|
-
```json
|
|
779
|
-
{
|
|
780
|
-
"success": true,
|
|
781
|
-
"tokens": [
|
|
782
|
-
{
|
|
783
|
-
"id": 42,
|
|
784
|
-
"name": "CI/CD Pipeline Token",
|
|
785
|
-
"prefix": "mbk_7f83a92",
|
|
786
|
-
"scope": "read-only",
|
|
787
|
-
"allowedApps": ["App1", "App2"],
|
|
788
|
-
"lastUsed": "2025-01-27T10:15:30.000Z",
|
|
789
|
-
"createdAt": "2025-01-27T12:34:56.000Z",
|
|
790
|
-
"expiresAt": "2025-04-27T12:34:56.000Z",
|
|
791
|
-
"expired": false
|
|
792
|
-
},
|
|
793
|
-
{
|
|
794
|
-
"id": 43,
|
|
795
|
-
"name": "Admin API Token",
|
|
796
|
-
"prefix": "mbk_a1b2c3d",
|
|
797
|
-
"scope": "write",
|
|
798
|
-
"allowedApps": null,
|
|
799
|
-
"lastUsed": null,
|
|
800
|
-
"createdAt": "2025-01-26T08:20:15.000Z",
|
|
801
|
-
"expiresAt": null,
|
|
802
|
-
"expired": false
|
|
803
|
-
}
|
|
804
|
-
],
|
|
805
|
-
"count": 2
|
|
806
|
-
}
|
|
807
|
-
```
|
|
808
|
-
|
|
809
|
-
**Note:** `allowedApps: null` means the token inherits from user's allowed apps.
|
|
810
|
-
|
|
811
|
-
**Error Responses:**
|
|
812
|
-
|
|
813
|
-
| Status Code | Error Code | Message |
|
|
814
|
-
|------------|------------|---------|
|
|
815
|
-
| 401 | SESSION_NOT_FOUND | Not authenticated |
|
|
816
|
-
| 500 | INTERNAL_SERVER_ERROR | Internal Server Error |
|
|
817
|
-
|
|
818
|
-
---
|
|
819
|
-
|
|
820
|
-
##### `DELETE /mbkauthe/api/token/:id`
|
|
821
|
-
|
|
822
|
-
Revoke (delete) an API token by its ID.
|
|
823
|
-
|
|
824
|
-
**Rate Limit:** 10 requests per minute
|
|
825
|
-
|
|
826
|
-
**Authentication:** Session required (cookie or Bearer token)
|
|
827
|
-
|
|
828
|
-
**URL Parameters:**
|
|
829
|
-
- `id`: Token ID (integer)
|
|
830
|
-
|
|
831
|
-
**Success Response (200 OK):**
|
|
832
|
-
```json
|
|
833
|
-
{
|
|
834
|
-
"success": true,
|
|
835
|
-
"message": "Token revoked successfully"
|
|
836
|
-
}
|
|
837
|
-
```
|
|
838
|
-
|
|
839
|
-
**Error Responses:**
|
|
840
|
-
|
|
841
|
-
| Status Code | Error Code | Message |
|
|
842
|
-
|------------|------------|---------|
|
|
843
|
-
| 400 | MISSING_REQUIRED_FIELD | Invalid token ID |
|
|
844
|
-
| 401 | SESSION_NOT_FOUND | Not authenticated |
|
|
845
|
-
| 404 | SESSION_NOT_FOUND | Token not found or not owned by you |
|
|
846
|
-
| 500 | INTERNAL_SERVER_ERROR | Internal Server Error |
|
|
847
|
-
|
|
848
|
-
---
|
|
849
|
-
|
|
850
|
-
### Multi-Account Endpoints
|
|
851
|
-
|
|
852
701
|
#### `GET /mbkauthe/accounts`
|
|
853
702
|
|
|
854
703
|
Renders the account switching page, allowing users to switch between remembered accounts on the device.
|
|
@@ -1130,6 +979,8 @@ Serves the application's SVG icon file from the root level.
|
|
|
1130
979
|
|
|
1131
980
|
**Note:** This route is mounted at the root level (not under `/mbkauthe`)
|
|
1132
981
|
|
|
982
|
+
**Also served:** `/favicon.ico` and `/icon.png` are provided as additional icon fallbacks at the same root level.
|
|
983
|
+
|
|
1133
984
|
**Usage:**
|
|
1134
985
|
```html
|
|
1135
986
|
<img src="/icon.svg" alt="App Icon">
|
package/docs/db.md
CHANGED
|
@@ -88,4 +88,4 @@ const encryptedPassword = hashPassword("your-password", "newusername");
|
|
|
88
88
|
// INSERT ... "PasswordEnc" = encryptedPassword (see column list in db.sql)
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
Replace usernames, roles (`SuperAdmin`, `NormalUser`, `Guest`, `member`), and flags (`Active`, `HaveMailAccount`) to match your needs.
|
|
91
|
+
Replace usernames, roles (`SuperAdmin`, `NormalUser`, `Guest`, `member`), and flags (`Active`, `HaveMailAccount`) to match your needs.
|