@privateaim/server-http-kit 0.8.3 → 0.8.5
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/CHANGELOG.md +52 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middlewares/error.d.ts.map +1 -1
- package/dist/middlewares/error.js +38 -10
- package/dist/middlewares/error.js.map +1 -1
- package/dist/middlewares/force-logged-in.d.ts.map +1 -1
- package/dist/middlewares/force-logged-in.js +1 -5
- package/dist/middlewares/force-logged-in.js.map +1 -1
- package/dist/middlewares/rate-limit.d.ts.map +1 -1
- package/dist/middlewares/rate-limit.js +8 -12
- package/dist/middlewares/rate-limit.js.map +1 -1
- package/dist/request/identity-realm.d.ts +8 -0
- package/dist/request/identity-realm.d.ts.map +1 -0
- package/dist/request/identity-realm.js +21 -0
- package/dist/request/identity-realm.js.map +1 -0
- package/dist/request/identity.d.ts +7 -0
- package/dist/request/identity.d.ts.map +1 -0
- package/dist/request/identity.js +32 -0
- package/dist/request/identity.js.map +1 -0
- package/dist/request/index.d.ts +3 -0
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +3 -0
- package/dist/request/index.js.map +1 -1
- package/dist/request/permission/helper.d.ts +5 -0
- package/dist/request/permission/helper.d.ts.map +1 -0
- package/dist/request/permission/helper.js +23 -0
- package/dist/request/permission/helper.js.map +1 -0
- package/dist/request/permission/index.d.ts +3 -0
- package/dist/request/permission/index.d.ts.map +1 -0
- package/dist/{validation → request/permission}/index.js +2 -4
- package/dist/request/permission/index.js.map +1 -0
- package/dist/request/permission/module.d.ts +13 -0
- package/dist/request/permission/module.d.ts.map +1 -0
- package/dist/request/permission/module.js +47 -0
- package/dist/request/permission/module.js.map +1 -0
- package/dist/request/types.d.ts +11 -12
- package/dist/request/types.d.ts.map +1 -1
- package/dist/services/authup/middleware.js +3 -3
- package/dist/services/authup/middleware.js.map +1 -1
- package/dist/services/authup/permission-provider.d.ts +5 -0
- package/dist/services/authup/permission-provider.d.ts.map +1 -0
- package/dist/services/authup/permission-provider.js +20 -0
- package/dist/services/authup/permission-provider.js.map +1 -0
- package/dist/services/authup/utils.d.ts +2 -2
- package/dist/services/authup/utils.d.ts.map +1 -1
- package/dist/services/authup/utils.js +21 -33
- package/dist/services/authup/utils.js.map +1 -1
- package/package.json +16 -16
- package/{dist/validation/type.js → src/constants.ts} +6 -4
- package/src/index.ts +1 -1
- package/src/middlewares/error.ts +46 -12
- package/src/middlewares/force-logged-in.ts +2 -8
- package/src/middlewares/rate-limit.ts +11 -16
- package/src/request/identity-realm.ts +26 -0
- package/src/request/identity.ts +33 -0
- package/src/request/index.ts +3 -0
- package/src/request/permission/helper.ts +24 -0
- package/src/{validation → request/permission}/index.ts +2 -4
- package/src/request/permission/module.ts +60 -0
- package/src/request/types.ts +12 -10
- package/src/services/authup/middleware.ts +3 -3
- package/src/services/authup/permission-provider.ts +18 -0
- package/src/services/authup/utils.ts +27 -39
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/message.d.ts +0 -2
- package/dist/validation/message.d.ts.map +0 -1
- package/dist/validation/message.js +0 -17
- package/dist/validation/message.js.map +0 -1
- package/dist/validation/module.d.ts +0 -6
- package/dist/validation/module.d.ts.map +0 -1
- package/dist/validation/module.js +0 -45
- package/dist/validation/module.js.map +0 -1
- package/dist/validation/result.d.ts +0 -7
- package/dist/validation/result.d.ts.map +0 -1
- package/dist/validation/result.js +0 -43
- package/dist/validation/result.js.map +0 -1
- package/dist/validation/type.d.ts +0 -15
- package/dist/validation/type.d.ts.map +0 -1
- package/dist/validation/type.js.map +0 -1
- package/src/validation/message.ts +0 -17
- package/src/validation/module.ts +0 -49
- package/src/validation/result.ts +0 -58
- package/src/validation/type.ts +0 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/services/authup/middleware.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,sDA4FC;AApGD,
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/services/authup/middleware.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PermissionGetOptions, PermissionItem, PermissionProvider } from '@authup/access';
|
|
2
|
+
export declare class FakePermissionProvider implements PermissionProvider {
|
|
3
|
+
get(criteria: PermissionGetOptions): Promise<PermissionItem | undefined>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=permission-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-provider.d.ts","sourceRoot":"","sources":["../../../src/services/authup/permission-provider.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/F,qBAAa,sBAAuB,YAAW,kBAAkB;IACvD,GAAG,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;CAOjF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FakePermissionProvider = void 0;
|
|
10
|
+
class FakePermissionProvider {
|
|
11
|
+
async get(criteria) {
|
|
12
|
+
return {
|
|
13
|
+
name: criteria.name,
|
|
14
|
+
realm_id: criteria.realmId,
|
|
15
|
+
policy: null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FakePermissionProvider = FakePermissionProvider;
|
|
20
|
+
//# sourceMappingURL=permission-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-provider.js","sourceRoot":"","sources":["../../../src/services/authup/permission-provider.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,MAAa,sBAAsB;IAC/B,KAAK,CAAC,GAAG,CAAC,QAA8B;QACpC,OAAO;YACH,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,QAAQ,EAAE,QAAQ,CAAC,OAAO;YAC1B,MAAM,EAAE,IAAI;SACf,CAAC;IACN,CAAC;CACJ;AARD,wDAQC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { TokenVerificationData } from '@authup/server-
|
|
1
|
+
import type { TokenVerificationData } from '@authup/server-adapter-kit';
|
|
2
2
|
import type { Request } from 'routup';
|
|
3
|
-
type TokenVerificationDataMinimal = Pick<TokenVerificationData, 'permissions' | 'realm_id' | 'realm_name' | 'sub' | 'sub_kind' | 'sub_name'>;
|
|
3
|
+
type TokenVerificationDataMinimal = Pick<TokenVerificationData, 'permissions' | 'realm_id' | 'realm_name' | 'sub' | 'sub_kind' | 'sub_name' | 'scope'>;
|
|
4
4
|
export declare function createFakeTokenVerificationData(): TokenVerificationDataMinimal;
|
|
5
5
|
export declare function applyTokenVerificationData(req: Request, data: TokenVerificationDataMinimal, fakeAbilities?: boolean): void;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAItC,KAAK,4BAA4B,GAAG,IAAI,CACxC,qBAAqB,EACrB,aAAa,GACb,UAAU,GACV,YAAY,GACZ,KAAK,GACL,UAAU,GACV,UAAU,GACV,OAAO,CACN,CAAC;AAEF,wBAAgB,+BAA+B,IAAI,4BAA4B,CAW9E;AAED,wBAAgB,0BAA0B,CACtC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,4BAA4B,EAClC,aAAa,CAAC,EAAE,OAAO,QA2B1B"}
|
|
@@ -8,18 +8,10 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createFakeTokenVerificationData = createFakeTokenVerificationData;
|
|
10
10
|
exports.applyTokenVerificationData = applyTokenVerificationData;
|
|
11
|
-
const
|
|
11
|
+
const access_1 = require("@authup/access");
|
|
12
12
|
const core_kit_1 = require("@authup/core-kit");
|
|
13
|
-
const kit_2 = require("@privateaim/kit");
|
|
14
13
|
const request_1 = require("../../request");
|
|
15
|
-
|
|
16
|
-
return Object.values({
|
|
17
|
-
...kit_2.PermissionName,
|
|
18
|
-
...core_kit_1.PermissionName,
|
|
19
|
-
}).map((name) => ({
|
|
20
|
-
name,
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
14
|
+
const permission_provider_1 = require("./permission-provider");
|
|
23
15
|
function createFakeTokenVerificationData() {
|
|
24
16
|
return {
|
|
25
17
|
realm_id: 'd94b2f28-29e3-4ced-b8f1-6923a01dc1ee',
|
|
@@ -27,36 +19,32 @@ function createFakeTokenVerificationData() {
|
|
|
27
19
|
sub_kind: 'user',
|
|
28
20
|
sub: 'd94b2f28-29e3-4ced-b8f1-6923a01dc1ee',
|
|
29
21
|
sub_name: 'admin',
|
|
30
|
-
permissions:
|
|
22
|
+
permissions: [],
|
|
31
23
|
};
|
|
32
24
|
}
|
|
33
25
|
function applyTokenVerificationData(req, data, fakeAbilities) {
|
|
34
|
-
let
|
|
26
|
+
let provider;
|
|
35
27
|
if (fakeAbilities) {
|
|
36
|
-
|
|
28
|
+
provider = new permission_provider_1.FakePermissionProvider();
|
|
37
29
|
}
|
|
38
30
|
else {
|
|
39
|
-
|
|
31
|
+
provider = new access_1.PermissionMemoryProvider(data.permissions);
|
|
40
32
|
}
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
(0, request_1.setRequestEnv)(req, 'realmId', data.realm_id);
|
|
44
|
-
(0, request_1.setRequestEnv)(req, 'realmName', data.realm_name);
|
|
45
|
-
(0, request_1.setRequestEnv)(req, 'realm', {
|
|
46
|
-
id: data.realm_id,
|
|
47
|
-
name: data.realm_name,
|
|
33
|
+
const permissionChecker = new access_1.PermissionChecker({
|
|
34
|
+
provider,
|
|
48
35
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
36
|
+
const requestPermissionChecker = new request_1.RequestPermissionChecker(req, permissionChecker);
|
|
37
|
+
(0, request_1.setRequestEnv)(req, 'permissionChecker', requestPermissionChecker);
|
|
38
|
+
(0, request_1.setRequestEnv)(req, 'identity', {
|
|
39
|
+
id: data.sub,
|
|
40
|
+
type: data.sub_kind,
|
|
41
|
+
realmId: data.realm_id,
|
|
42
|
+
realmName: data.realm_name,
|
|
43
|
+
attributes: {
|
|
44
|
+
id: data.sub,
|
|
45
|
+
name: data.sub_name,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
(0, request_1.setRequestEnv)(req, 'scopes', (0, core_kit_1.transformOAuth2ScopeToArray)(data.scope));
|
|
61
49
|
}
|
|
62
50
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAqBH,0EAWC;AAED,gEA8BC;AA7DD,2CAA6E;AAC7E,+CAAkF;AAGlF,2CAAwE;AACxE,+DAA+D;AAa/D,SAAgB,+BAA+B;IAC3C,OAAO;QACH,QAAQ,EAAE,sCAAsC;QAChD,UAAU,EAAE,4BAAiB;QAE7B,QAAQ,EAAE,MAAM;QAChB,GAAG,EAAE,sCAAsC;QAC3C,QAAQ,EAAE,OAAO;QAEjB,WAAW,EAAE,EAAE;KAClB,CAAC;AACN,CAAC;AAED,SAAgB,0BAA0B,CACtC,GAAY,EACZ,IAAkC,EAClC,aAAuB;IAEvB,IAAI,QAA6B,CAAC;IAClC,IAAI,aAAa,EAAE,CAAC;QAChB,QAAQ,GAAG,IAAI,4CAAsB,EAAE,CAAC;IAC5C,CAAC;SAAM,CAAC;QACJ,QAAQ,GAAG,IAAI,iCAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,iBAAiB,GAAG,IAAI,0BAAiB,CAAC;QAC5C,QAAQ;KACX,CAAC,CAAC;IACH,MAAM,wBAAwB,GAAG,IAAI,kCAAwB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;IACtF,IAAA,uBAAa,EAAC,GAAG,EAAE,mBAAmB,EAAE,wBAAwB,CAAC,CAAC;IAElE,IAAA,uBAAa,EAAC,GAAG,EAAE,UAAU,EAAE;QAC3B,EAAE,EAAE,IAAI,CAAC,GAAG;QACZ,IAAI,EAAE,IAAI,CAAC,QAAQ;QACnB,OAAO,EAAE,IAAI,CAAC,QAAQ;QACtB,SAAS,EAAE,IAAI,CAAC,UAAU;QAC1B,UAAU,EAAE;YACR,EAAE,EAAE,IAAI,CAAC,GAAG;YACZ,IAAI,EAAE,IAAI,CAAC,QAAQ;SACtB;KACJ,CAAC,CAAC;IAEH,IAAA,uBAAa,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAA,sCAA2B,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privateaim/server-http-kit",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": {
|
|
@@ -11,35 +11,35 @@
|
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"description": "This package contains the realtime application which connects the API with socket based clients.",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@authup/
|
|
15
|
-
"@authup/
|
|
16
|
-
"@authup/core-
|
|
17
|
-
"@authup/
|
|
18
|
-
"@authup/server-
|
|
14
|
+
"@authup/access": "^1.0.0-beta.24",
|
|
15
|
+
"@authup/kit": "^1.0.0-beta.24",
|
|
16
|
+
"@authup/core-kit": "^1.0.0-beta.24",
|
|
17
|
+
"@authup/core-http-kit": "^1.0.0-beta.24",
|
|
18
|
+
"@authup/server-adapter-kit": "^1.0.0-beta.24",
|
|
19
|
+
"@authup/server-adapter-http": "^1.0.0-beta.24",
|
|
19
20
|
"@ebec/http": "^2.3.0",
|
|
20
|
-
"@privateaim/kit": "^0.8.
|
|
21
|
-
"@privateaim/server-kit": "^0.8.
|
|
21
|
+
"@privateaim/kit": "^0.8.5",
|
|
22
|
+
"@privateaim/server-kit": "^0.8.5",
|
|
22
23
|
"@routup/basic": "^1.4.1",
|
|
23
24
|
"@routup/decorators": "^3.4.1",
|
|
24
25
|
"@routup/prometheus": "^2.4.0",
|
|
25
26
|
"@routup/rate-limit": "^2.4.0",
|
|
26
27
|
"@routup/swagger": "^2.4.1",
|
|
27
28
|
"cors": "^2.8.5",
|
|
28
|
-
"hapic": "^2.5.
|
|
29
|
-
"locter": "^2.1.
|
|
29
|
+
"hapic": "^2.5.2",
|
|
30
|
+
"locter": "^2.1.4",
|
|
31
|
+
"validup": "^0.1.8"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@types/cors": "^2.8.17",
|
|
33
|
-
"
|
|
34
|
-
"redis-extension": "^1.5.0",
|
|
35
|
+
"redis-extension": "^2.0.1",
|
|
35
36
|
"routup": "^4.0.1",
|
|
36
|
-
"typeorm-extension": "^3.6.
|
|
37
|
+
"typeorm-extension": "^3.6.2"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"redis-extension": "^1.5.0",
|
|
40
|
+
"redis-extension": "^2.0.1",
|
|
41
41
|
"routup": "^4.0.1",
|
|
42
|
-
"typeorm-extension": "^3.6.
|
|
42
|
+
"typeorm-extension": "^3.6.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"dev": "ts-node src/index.ts",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024.
|
|
4
3
|
* Author Peter Placzek (tada5hi)
|
|
5
4
|
* For the full copyright and license information,
|
|
6
5
|
* view the LICENSE file that was distributed with this source code.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
export enum HTTPHandlerOperation {
|
|
9
|
+
CREATE = 'create',
|
|
10
|
+
UPDATE = 'update',
|
|
11
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export * from './constants';
|
|
8
9
|
export * from './middlewares';
|
|
9
10
|
export * from './request';
|
|
10
11
|
export * from './services';
|
|
11
12
|
export * from './swagger';
|
|
12
|
-
export * from './validation';
|
package/src/middlewares/error.ts
CHANGED
|
@@ -5,13 +5,54 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { BuiltInPolicyType, PermissionError } from '@authup/access';
|
|
8
9
|
import { isObject } from '@privateaim/kit';
|
|
9
10
|
import type { Router } from 'routup';
|
|
10
11
|
import { errorHandler } from 'routup';
|
|
11
12
|
import { useLogger } from '@privateaim/server-kit';
|
|
13
|
+
import { EntityRelationLookupError } from 'typeorm-extension';
|
|
14
|
+
import { ValidupNestedError } from 'validup';
|
|
12
15
|
|
|
13
16
|
export function mountErrorMiddleware(router: Router) {
|
|
14
17
|
router.use(errorHandler((error, req, res) => {
|
|
18
|
+
const isServerError = error.statusCode >= 500 &&
|
|
19
|
+
error.statusCode < 600;
|
|
20
|
+
|
|
21
|
+
if (isServerError || error.logMessage) {
|
|
22
|
+
useLogger().error(error);
|
|
23
|
+
|
|
24
|
+
if (error.cause) {
|
|
25
|
+
useLogger().error(error.cause);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (error.cause instanceof PermissionError) {
|
|
30
|
+
error.expose = true;
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
error.cause.policy &&
|
|
34
|
+
error.cause.policy.type === BuiltInPolicyType.IDENTITY
|
|
35
|
+
) {
|
|
36
|
+
error.statusCode = 401;
|
|
37
|
+
} else {
|
|
38
|
+
error.statusCode = 403;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (error.cause instanceof EntityRelationLookupError) {
|
|
43
|
+
error.expose = true;
|
|
44
|
+
error.statusCode = 400;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (error.cause instanceof ValidupNestedError) {
|
|
48
|
+
error.expose = true;
|
|
49
|
+
error.statusCode = 400;
|
|
50
|
+
error.data = {
|
|
51
|
+
children: error.cause.children,
|
|
52
|
+
attributes: error.cause.children.map((child) => child.pathAbsolute),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
15
56
|
// catch and decorate some db errors :)
|
|
16
57
|
switch (error.code) {
|
|
17
58
|
case 'ER_DUP_ENTRY':
|
|
@@ -28,18 +69,11 @@ export function mountErrorMiddleware(router: Router) {
|
|
|
28
69
|
break;
|
|
29
70
|
}
|
|
30
71
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (isServerError || error.logMessage) {
|
|
35
|
-
useLogger().error(error);
|
|
36
|
-
|
|
37
|
-
if (error.cause) {
|
|
38
|
-
useLogger().error(error.cause);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
72
|
+
const exposeError = typeof error.expose === 'boolean' ?
|
|
73
|
+
error.expose :
|
|
74
|
+
!isServerError;
|
|
41
75
|
|
|
42
|
-
if (
|
|
76
|
+
if (!exposeError) {
|
|
43
77
|
error.message = 'An internal server error occurred.';
|
|
44
78
|
}
|
|
45
79
|
|
|
@@ -49,7 +83,7 @@ export function mountErrorMiddleware(router: Router) {
|
|
|
49
83
|
statusCode: error.statusCode,
|
|
50
84
|
code: `${error.code}`,
|
|
51
85
|
message: error.message,
|
|
52
|
-
...(isObject(error.data)
|
|
86
|
+
...(exposeError && isObject(error.data) ? error.data : {}),
|
|
53
87
|
};
|
|
54
88
|
}));
|
|
55
89
|
}
|
|
@@ -5,21 +5,15 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { UnauthorizedError } from '@ebec/http';
|
|
9
8
|
import type { HandlerInterface } from '@routup/decorators';
|
|
10
9
|
import type {
|
|
11
10
|
Next, Request, Response,
|
|
12
11
|
} from 'routup';
|
|
13
|
-
import {
|
|
12
|
+
import { useRequestIdentityOrFail } from '../request';
|
|
14
13
|
|
|
15
14
|
export class ForceLoggedInMiddleware implements HandlerInterface {
|
|
16
15
|
public run(request: Request, response: Response, next: Next) {
|
|
17
|
-
|
|
18
|
-
typeof useRequestEnv(request, 'userId') === 'undefined' &&
|
|
19
|
-
typeof useRequestEnv(request, 'robotId') === 'undefined'
|
|
20
|
-
) {
|
|
21
|
-
throw new UnauthorizedError();
|
|
22
|
-
}
|
|
16
|
+
useRequestIdentityOrFail(request);
|
|
23
17
|
|
|
24
18
|
next();
|
|
25
19
|
}
|
|
@@ -9,32 +9,27 @@ import { REALM_MASTER_NAME } from '@authup/core-kit';
|
|
|
9
9
|
import type { OptionsInput } from '@routup/rate-limit';
|
|
10
10
|
import { rateLimit } from '@routup/rate-limit';
|
|
11
11
|
import type { Request, Router } from 'routup';
|
|
12
|
-
import {
|
|
12
|
+
import { useRequestIdentity } from '../request';
|
|
13
13
|
|
|
14
14
|
export function mountRateLimiterMiddleware(router: Router) {
|
|
15
15
|
const options : OptionsInput = {
|
|
16
16
|
skip(req: Request) {
|
|
17
|
-
const
|
|
18
|
-
if (robot) {
|
|
19
|
-
const { name } = useRequestEnv(req, 'realm');
|
|
17
|
+
const identity = useRequestIdentity(req);
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false;
|
|
19
|
+
return identity &&
|
|
20
|
+
identity.type === 'robot' &&
|
|
21
|
+
identity.realmName === REALM_MASTER_NAME;
|
|
30
22
|
},
|
|
31
23
|
max(req: Request) {
|
|
32
|
-
|
|
24
|
+
const identity = useRequestIdentity(req);
|
|
25
|
+
if (identity && identity.type === 'user') {
|
|
33
26
|
return 60 * 100; // 100 req p. sec
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
if (
|
|
30
|
+
identity &&
|
|
31
|
+
(identity.type === 'robot' || identity.type === 'client')
|
|
32
|
+
) {
|
|
38
33
|
return 60 * 1000; // 1000 req p. sec
|
|
39
34
|
}
|
|
40
35
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Request } from 'routup';
|
|
9
|
+
import { useRequestIdentity } from './identity';
|
|
10
|
+
|
|
11
|
+
type RequestRealm = {
|
|
12
|
+
id: string,
|
|
13
|
+
name: string
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function useRequestIdentityRealm(req: Request) : RequestRealm {
|
|
17
|
+
const identity = useRequestIdentity(req);
|
|
18
|
+
if (!identity) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
id: identity.realmId,
|
|
24
|
+
name: identity.realmName,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { REALM_MASTER_NAME } from '@authup/core-kit';
|
|
9
|
+
import { UnauthorizedError } from '@ebec/http';
|
|
10
|
+
import type { Request } from 'routup';
|
|
11
|
+
import type { RequestIdentity } from './types';
|
|
12
|
+
import { setRequestEnv, useRequestEnv } from './env';
|
|
13
|
+
|
|
14
|
+
export function useRequestIdentity(req: Request) : RequestIdentity | undefined {
|
|
15
|
+
return useRequestEnv(req, 'identity');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function setRequestIdentity(req: Request, identity: RequestIdentity) : void {
|
|
19
|
+
setRequestEnv(req, 'identity', identity);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useRequestIdentityOrFail(req: Request) : RequestIdentity {
|
|
23
|
+
const identity = useRequestIdentity(req);
|
|
24
|
+
if (!identity) {
|
|
25
|
+
throw new UnauthorizedError();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return identity;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isRequestIdentityMasterRealmMember(input: RequestIdentity) : boolean {
|
|
32
|
+
return input.realmName === REALM_MASTER_NAME;
|
|
33
|
+
}
|
package/src/request/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Request } from 'routup';
|
|
9
|
+
import { BadRequestError } from '@ebec/http';
|
|
10
|
+
import { setRequestEnv, useRequestEnv } from '../env';
|
|
11
|
+
import type { RequestPermissionChecker } from './module';
|
|
12
|
+
|
|
13
|
+
export function setRequestPermissionChecker(req: Request, checker: RequestPermissionChecker) {
|
|
14
|
+
setRequestEnv(req, 'permissionChecker', checker);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useRequestPermissionChecker(req: Request) : RequestPermissionChecker {
|
|
18
|
+
const checker = useRequestEnv(req, 'permissionChecker');
|
|
19
|
+
if (!checker) {
|
|
20
|
+
throw new BadRequestError('The request permission checker is not initialized.');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return checker;
|
|
24
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
3
|
* Author Peter Placzek (tada5hi)
|
|
4
4
|
* For the full copyright and license information,
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './helper';
|
|
9
9
|
export * from './module';
|
|
10
|
-
export * from './type';
|
|
11
|
-
export * from './result';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ScopeName } from '@authup/core-kit';
|
|
9
|
+
import type {
|
|
10
|
+
PermissionChecker,
|
|
11
|
+
PermissionCheckerCheckContext,
|
|
12
|
+
} from '@authup/access';
|
|
13
|
+
import type { Request } from 'routup';
|
|
14
|
+
import { useRequestEnv } from '../env';
|
|
15
|
+
import { useRequestIdentity } from '../identity';
|
|
16
|
+
|
|
17
|
+
export class RequestPermissionChecker {
|
|
18
|
+
protected req: Request;
|
|
19
|
+
|
|
20
|
+
protected checker: PermissionChecker;
|
|
21
|
+
|
|
22
|
+
constructor(req: Request, checker: PermissionChecker) {
|
|
23
|
+
this.req = req;
|
|
24
|
+
this.checker = checker;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// --------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
async check(ctx: PermissionCheckerCheckContext) : Promise<void> {
|
|
30
|
+
return this.checker.check(this.extendCheckContext(ctx));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async preCheck(ctx: PermissionCheckerCheckContext) : Promise<void> {
|
|
34
|
+
return this.checker.preCheck(this.extendCheckContext(ctx));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// --------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
async preCheckOneOf(ctx: PermissionCheckerCheckContext) : Promise<void> {
|
|
40
|
+
return this.checker.preCheckOneOf(this.extendCheckContext(ctx));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async checkOneOf(ctx: PermissionCheckerCheckContext) : Promise<void> {
|
|
44
|
+
return this.checker.checkOneOf(this.extendCheckContext(ctx));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// --------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
protected extendCheckContext(ctx: PermissionCheckerCheckContext) {
|
|
50
|
+
const scopes = useRequestEnv(this.req, 'scopes') || [];
|
|
51
|
+
if (scopes.indexOf(ScopeName.GLOBAL) !== -1) {
|
|
52
|
+
ctx.data = {
|
|
53
|
+
...ctx.data || {},
|
|
54
|
+
identity: useRequestIdentity(this.req),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return ctx;
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/request/types.ts
CHANGED
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { RequestPermissionChecker } from './permission';
|
|
9
9
|
|
|
10
|
-
export type
|
|
11
|
-
|
|
10
|
+
export type RequestIdentity = {
|
|
11
|
+
id: string;
|
|
12
|
+
type: 'user' | 'client' | 'robot',
|
|
13
|
+
realmId: string,
|
|
14
|
+
realmName: string
|
|
15
|
+
attributes?: Record<string, any>,
|
|
16
|
+
};
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
realm?: { id?: string, name?: string },
|
|
18
|
+
export type RequestEnv = {
|
|
19
|
+
permissionChecker?: RequestPermissionChecker,
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
userName?: string,
|
|
21
|
+
identity?: RequestIdentity,
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
robotName?: string
|
|
23
|
+
scopes?: string[],
|
|
22
24
|
};
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { TokenCreatorOptions } from '@authup/core-http-kit';
|
|
9
|
-
import type { TokenVerifierRedisCacheOptions } from '@authup/server-
|
|
10
|
-
import { createMiddleware } from '@authup/server-
|
|
9
|
+
import type { TokenVerifierRedisCacheOptions } from '@authup/server-adapter-kit';
|
|
10
|
+
import { createMiddleware } from '@authup/server-adapter-http';
|
|
11
11
|
import { useRequestCookie } from '@routup/basic/cookie';
|
|
12
12
|
import { parseAuthorizationHeader } from 'hapic';
|
|
13
13
|
import type { Router } from 'routup';
|
|
@@ -50,7 +50,7 @@ export function mountAuthupMiddleware(
|
|
|
50
50
|
const header = parseAuthorizationHeader(headerRaw);
|
|
51
51
|
|
|
52
52
|
if (header.type === 'Basic') {
|
|
53
|
-
const token = await options.client.token.
|
|
53
|
+
const token = await options.client.token.createWithPassword({
|
|
54
54
|
username: header.username,
|
|
55
55
|
password: header.password,
|
|
56
56
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PermissionGetOptions, PermissionItem, PermissionProvider } from '@authup/access';
|
|
9
|
+
|
|
10
|
+
export class FakePermissionProvider implements PermissionProvider {
|
|
11
|
+
async get(criteria: PermissionGetOptions): Promise<PermissionItem | undefined> {
|
|
12
|
+
return {
|
|
13
|
+
name: criteria.name,
|
|
14
|
+
realm_id: criteria.realmId,
|
|
15
|
+
policy: null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|