@privateaim/server-http-kit 0.8.3 → 0.8.4
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 +25 -0
- package/dist/middlewares/error.d.ts.map +1 -1
- package/dist/middlewares/error.js +30 -11
- 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/request/permission/index.js +25 -0
- 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 +2 -2
- package/dist/services/authup/middleware.js.map +1 -1
- 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 +15 -19
- package/dist/services/authup/utils.js.map +1 -1
- package/package.json +11 -11
- package/src/middlewares/error.ts +36 -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/request/permission/index.ts +9 -0
- package/src/request/permission/module.ts +60 -0
- package/src/request/types.ts +12 -10
- package/src/services/authup/middleware.ts +2 -2
- package/src/services/authup/utils.ts +25 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.4](https://github.com/PrivateAIM/hub/compare/v0.8.3...v0.8.4) (2024-10-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* bump authup & implement async policy & permission evaluation ([#807](https://github.com/PrivateAIM/hub/issues/807)) ([d065562](https://github.com/PrivateAIM/hub/commit/d065562585076e26553ad5a39f4a5789f7e18f24))
|
|
9
|
+
* bump authup & vuecs packages + refactored navigation ([c4db8d5](https://github.com/PrivateAIM/hub/commit/c4db8d51588b3d701815e2ba2f9b80e594f3663f))
|
|
10
|
+
* handle permission-/policy-error in error middleware ([4b4fae4](https://github.com/PrivateAIM/hub/commit/4b4fae4fd048ddf9509af3d611a201484b0d4eaf))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* condition for exposing error via middleware ([e7a5fee](https://github.com/PrivateAIM/hub/commit/e7a5feec09eec7f63c91e13781b4abc19cb787f6))
|
|
16
|
+
* **deps:** bump locter from 2.1.1 to 2.1.2 ([#795](https://github.com/PrivateAIM/hub/issues/795)) ([fdb8cba](https://github.com/PrivateAIM/hub/commit/fdb8cba0c5a991a57ed9a26a324b9f2fed6caf5c))
|
|
17
|
+
* **deps:** bump locter from 2.1.2 to 2.1.4 ([#816](https://github.com/PrivateAIM/hub/issues/816)) ([0af403a](https://github.com/PrivateAIM/hub/commit/0af403a0eef7bca9c4f316e6598607c2897a8065))
|
|
18
|
+
* **deps:** bump typeorm-extension from 3.6.1 to 3.6.2 ([#810](https://github.com/PrivateAIM/hub/issues/810)) ([c9af9ae](https://github.com/PrivateAIM/hub/commit/c9af9aea537c4a51aae13f1059c1565180045a83))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Dependencies
|
|
22
|
+
|
|
23
|
+
* The following workspace dependencies were updated
|
|
24
|
+
* dependencies
|
|
25
|
+
* @privateaim/kit bumped from ^0.8.3 to ^0.8.4
|
|
26
|
+
* @privateaim/server-kit bumped from ^0.8.3 to ^0.8.4
|
|
27
|
+
|
|
3
28
|
## [0.8.3](https://github.com/PrivateAIM/hub/compare/v0.8.2...v0.8.3) (2024-09-19)
|
|
4
29
|
|
|
5
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKrC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,QAgElD"}
|
|
@@ -7,11 +7,35 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.mountErrorMiddleware = mountErrorMiddleware;
|
|
10
|
-
const kit_1 = require("@
|
|
10
|
+
const kit_1 = require("@authup/kit");
|
|
11
|
+
const kit_2 = require("@privateaim/kit");
|
|
11
12
|
const routup_1 = require("routup");
|
|
12
13
|
const server_kit_1 = require("@privateaim/server-kit");
|
|
14
|
+
const typeorm_extension_1 = require("typeorm-extension");
|
|
13
15
|
function mountErrorMiddleware(router) {
|
|
14
16
|
router.use((0, routup_1.errorHandler)((error, req, res) => {
|
|
17
|
+
const isServerError = error.statusCode >= 500 &&
|
|
18
|
+
error.statusCode < 600;
|
|
19
|
+
if (isServerError || error.logMessage) {
|
|
20
|
+
(0, server_kit_1.useLogger)().error(error);
|
|
21
|
+
if (error.cause) {
|
|
22
|
+
(0, server_kit_1.useLogger)().error(error.cause);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (error.cause instanceof kit_1.PermissionError) {
|
|
26
|
+
error.expose = true;
|
|
27
|
+
if (error.cause.policy &&
|
|
28
|
+
error.cause.policy.type === kit_1.BuiltInPolicyType.IDENTITY) {
|
|
29
|
+
error.statusCode = 401;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
error.statusCode = 403;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (error.cause instanceof typeorm_extension_1.EntityRelationLookupError) {
|
|
36
|
+
error.expose = true;
|
|
37
|
+
error.statusCode = 400;
|
|
38
|
+
}
|
|
15
39
|
// catch and decorate some db errors :)
|
|
16
40
|
switch (error.code) {
|
|
17
41
|
case 'ER_DUP_ENTRY':
|
|
@@ -27,15 +51,10 @@ function mountErrorMiddleware(router) {
|
|
|
27
51
|
error.expose = true;
|
|
28
52
|
break;
|
|
29
53
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (error.cause) {
|
|
35
|
-
(0, server_kit_1.useLogger)().error(error.cause);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (isServerError) {
|
|
54
|
+
const exposeError = typeof error.expose === 'boolean' ?
|
|
55
|
+
error.expose :
|
|
56
|
+
!isServerError;
|
|
57
|
+
if (!exposeError) {
|
|
39
58
|
error.message = 'An internal server error occurred.';
|
|
40
59
|
}
|
|
41
60
|
res.statusCode = error.statusCode;
|
|
@@ -43,7 +62,7 @@ function mountErrorMiddleware(router) {
|
|
|
43
62
|
statusCode: error.statusCode,
|
|
44
63
|
code: `${error.code}`,
|
|
45
64
|
message: error.message,
|
|
46
|
-
...((0,
|
|
65
|
+
...(exposeError && (0, kit_2.isObject)(error.data) ? error.data : {}),
|
|
47
66
|
};
|
|
48
67
|
}));
|
|
49
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AASH,oDAgEC;AAvED,qCAAiE;AACjE,yCAA2C;AAE3C,mCAAsC;AACtC,uDAAmD;AACnD,yDAA8D;AAE9D,SAAgB,oBAAoB,CAAC,MAAc;IAC/C,MAAM,CAAC,GAAG,CAAC,IAAA,qBAAY,EAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACxC,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,IAAI,GAAG;YACzC,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC;QAE3B,IAAI,aAAa,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACpC,IAAA,sBAAS,GAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAEzB,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,IAAA,sBAAS,GAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC;QACL,CAAC;QAED,IAAI,KAAK,CAAC,KAAK,YAAY,qBAAe,EAAE,CAAC;YACzC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;YAEpB,IACI,KAAK,CAAC,KAAK,CAAC,MAAM;gBAClB,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,uBAAiB,CAAC,QAAQ,EACxD,CAAC;gBACC,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACJ,K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CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"force-logged-in.d.ts","sourceRoot":"","sources":["../../src/middlewares/force-logged-in.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"force-logged-in.d.ts","sourceRoot":"","sources":["../../src/middlewares/force-logged-in.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EACR,IAAI,EAAE,OAAO,EAAE,QAAQ,EAC1B,MAAM,QAAQ,CAAC;AAGhB,qBAAa,uBAAwB,YAAW,gBAAgB;IACrD,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI;CAK9D"}
|
|
@@ -7,14 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ForceLoggedInMiddleware = void 0;
|
|
10
|
-
const http_1 = require("@ebec/http");
|
|
11
10
|
const request_1 = require("../request");
|
|
12
11
|
class ForceLoggedInMiddleware {
|
|
13
12
|
run(request, response, next) {
|
|
14
|
-
|
|
15
|
-
typeof (0, request_1.useRequestEnv)(request, 'robotId') === 'undefined') {
|
|
16
|
-
throw new http_1.UnauthorizedError();
|
|
17
|
-
}
|
|
13
|
+
(0, request_1.useRequestIdentityOrFail)(request);
|
|
18
14
|
next();
|
|
19
15
|
}
|
|
20
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"force-logged-in.js","sourceRoot":"","sources":["../../src/middlewares/force-logged-in.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;
|
|
1
|
+
{"version":3,"file":"force-logged-in.js","sourceRoot":"","sources":["../../src/middlewares/force-logged-in.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAMH,wCAAsD;AAEtD,MAAa,uBAAuB;IACzB,GAAG,CAAC,OAAgB,EAAE,QAAkB,EAAE,IAAU;QACvD,IAAA,kCAAwB,EAAC,OAAO,CAAC,CAAC;QAElC,IAAI,EAAE,CAAC;IACX,CAAC;CACJ;AAND,0DAMC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/middlewares/rate-limit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG9C,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/middlewares/rate-limit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG9C,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,QA4BxD"}
|
|
@@ -13,22 +13,18 @@ const request_1 = require("../request");
|
|
|
13
13
|
function mountRateLimiterMiddleware(router) {
|
|
14
14
|
const options = {
|
|
15
15
|
skip(req) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(0, request_1.useRequestEnv)(req, 'robotName') === 'system') {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return false;
|
|
16
|
+
const identity = (0, request_1.useRequestIdentity)(req);
|
|
17
|
+
return identity &&
|
|
18
|
+
identity.type === 'robot' &&
|
|
19
|
+
identity.realmName === core_kit_1.REALM_MASTER_NAME;
|
|
25
20
|
},
|
|
26
21
|
max(req) {
|
|
27
|
-
|
|
22
|
+
const identity = (0, request_1.useRequestIdentity)(req);
|
|
23
|
+
if (identity && identity.type === 'user') {
|
|
28
24
|
return 60 * 100; // 100 req p. sec
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
if (identity &&
|
|
27
|
+
(identity.type === 'robot' || identity.type === 'client')) {
|
|
32
28
|
return 60 * 1000; // 1000 req p. sec
|
|
33
29
|
}
|
|
34
30
|
return 60 * 20; // 20 req p. sec
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/middlewares/rate-limit.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/middlewares/rate-limit.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,gEA4BC;AAlCD,+CAAqD;AAErD,mDAA+C;AAE/C,wCAAgD;AAEhD,SAAgB,0BAA0B,CAAC,MAAc;IACrD,MAAM,OAAO,GAAkB;QAC3B,IAAI,CAAC,GAAY;YACb,MAAM,QAAQ,GAAG,IAAA,4BAAkB,EAAC,GAAG,CAAC,CAAC;YAEzC,OAAO,QAAQ;gBACX,QAAQ,CAAC,IAAI,KAAK,OAAO;gBACzB,QAAQ,CAAC,SAAS,KAAK,4BAAiB,CAAC;QACjD,CAAC;QACD,GAAG,CAAC,GAAY;YACZ,MAAM,QAAQ,GAAG,IAAA,4BAAkB,EAAC,GAAG,CAAC,CAAC;YACzC,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBACvC,OAAO,EAAE,GAAG,GAAG,CAAC,CAAC,iBAAiB;YACtC,CAAC;YAED,IACI,QAAQ;gBACR,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,EAC3D,CAAC;gBACC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,kBAAkB;YACxC,CAAC;YAED,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB;QACpC,CAAC;QACD,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS;KACjC,CAAC;IAEF,MAAM,CAAC,GAAG,CAAC,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-realm.d.ts","sourceRoot":"","sources":["../../src/request/identity-realm.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGtC,KAAK,YAAY,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAA;CACf,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAI,YAAY,CAUnE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024.
|
|
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.useRequestIdentityRealm = useRequestIdentityRealm;
|
|
10
|
+
const identity_1 = require("./identity");
|
|
11
|
+
function useRequestIdentityRealm(req) {
|
|
12
|
+
const identity = (0, identity_1.useRequestIdentity)(req);
|
|
13
|
+
if (!identity) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
id: identity.realmId,
|
|
18
|
+
name: identity.realmName,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=identity-realm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-realm.js","sourceRoot":"","sources":["../../src/request/identity-realm.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAUH,0DAUC;AAjBD,yCAAgD;AAOhD,SAAgB,uBAAuB,CAAC,GAAY;IAChD,MAAM,QAAQ,GAAG,IAAA,6BAAkB,EAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO;QACH,EAAE,EAAE,QAAQ,CAAC,OAAO;QACpB,IAAI,EAAE,QAAQ,CAAC,SAAS;KAC3B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Request } from 'routup';
|
|
2
|
+
import type { RequestIdentity } from './types';
|
|
3
|
+
export declare function useRequestIdentity(req: Request): RequestIdentity | undefined;
|
|
4
|
+
export declare function setRequestIdentity(req: Request, identity: RequestIdentity): void;
|
|
5
|
+
export declare function useRequestIdentityOrFail(req: Request): RequestIdentity;
|
|
6
|
+
export declare function isRequestIdentityMasterRealmMember(input: RequestIdentity): boolean;
|
|
7
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/request/identity.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAI,eAAe,GAAG,SAAS,CAE7E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,GAAI,IAAI,CAEjF;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAI,eAAe,CAOvE;AAED,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,eAAe,GAAI,OAAO,CAEnF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024.
|
|
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.useRequestIdentity = useRequestIdentity;
|
|
10
|
+
exports.setRequestIdentity = setRequestIdentity;
|
|
11
|
+
exports.useRequestIdentityOrFail = useRequestIdentityOrFail;
|
|
12
|
+
exports.isRequestIdentityMasterRealmMember = isRequestIdentityMasterRealmMember;
|
|
13
|
+
const core_kit_1 = require("@authup/core-kit");
|
|
14
|
+
const http_1 = require("@ebec/http");
|
|
15
|
+
const env_1 = require("./env");
|
|
16
|
+
function useRequestIdentity(req) {
|
|
17
|
+
return (0, env_1.useRequestEnv)(req, 'identity');
|
|
18
|
+
}
|
|
19
|
+
function setRequestIdentity(req, identity) {
|
|
20
|
+
(0, env_1.setRequestEnv)(req, 'identity', identity);
|
|
21
|
+
}
|
|
22
|
+
function useRequestIdentityOrFail(req) {
|
|
23
|
+
const identity = useRequestIdentity(req);
|
|
24
|
+
if (!identity) {
|
|
25
|
+
throw new http_1.UnauthorizedError();
|
|
26
|
+
}
|
|
27
|
+
return identity;
|
|
28
|
+
}
|
|
29
|
+
function isRequestIdentityMasterRealmMember(input) {
|
|
30
|
+
return input.realmName === core_kit_1.REALM_MASTER_NAME;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/request/identity.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,gDAEC;AAED,gDAEC;AAED,4DAOC;AAED,gFAEC;AAzBD,+CAAqD;AACrD,qCAA+C;AAG/C,+BAAqD;AAErD,SAAgB,kBAAkB,CAAC,GAAY;IAC3C,OAAO,IAAA,mBAAa,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AAC1C,CAAC;AAED,SAAgB,kBAAkB,CAAC,GAAY,EAAE,QAAyB;IACtE,IAAA,mBAAa,EAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,wBAAwB,CAAC,GAAY;IACjD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,MAAM,IAAI,wBAAiB,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAgB,kCAAkC,CAAC,KAAsB;IACrE,OAAO,KAAK,CAAC,SAAS,KAAK,4BAAiB,CAAC;AACjD,CAAC"}
|
package/dist/request/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":"AAOA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC"}
|
package/dist/request/index.js
CHANGED
|
@@ -20,6 +20,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./permission"), exports);
|
|
23
24
|
__exportStar(require("./env"), exports);
|
|
25
|
+
__exportStar(require("./identity"), exports);
|
|
26
|
+
__exportStar(require("./identity-realm"), exports);
|
|
24
27
|
__exportStar(require("./types"), exports);
|
|
25
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,wCAAsB;AACtB,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,wCAAsB;AACtB,6CAA2B;AAC3B,mDAAiC;AACjC,0CAAwB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Request } from 'routup';
|
|
2
|
+
import type { RequestPermissionChecker } from './module';
|
|
3
|
+
export declare function setRequestPermissionChecker(req: Request, checker: RequestPermissionChecker): void;
|
|
4
|
+
export declare function useRequestPermissionChecker(req: Request): RequestPermissionChecker;
|
|
5
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/request/permission/helper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEzD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,wBAAwB,QAE1F;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,GAAI,wBAAwB,CAOnF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024.
|
|
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.setRequestPermissionChecker = setRequestPermissionChecker;
|
|
10
|
+
exports.useRequestPermissionChecker = useRequestPermissionChecker;
|
|
11
|
+
const http_1 = require("@ebec/http");
|
|
12
|
+
const env_1 = require("../env");
|
|
13
|
+
function setRequestPermissionChecker(req, checker) {
|
|
14
|
+
(0, env_1.setRequestEnv)(req, 'permissionChecker', checker);
|
|
15
|
+
}
|
|
16
|
+
function useRequestPermissionChecker(req) {
|
|
17
|
+
const checker = (0, env_1.useRequestEnv)(req, 'permissionChecker');
|
|
18
|
+
if (!checker) {
|
|
19
|
+
throw new http_1.BadRequestError('The request permission checker is not initialized.');
|
|
20
|
+
}
|
|
21
|
+
return checker;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/request/permission/helper.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAOH,kEAEC;AAED,kEAOC;AAfD,qCAA6C;AAC7C,gCAAsD;AAGtD,SAAgB,2BAA2B,CAAC,GAAY,EAAE,OAAiC;IACvF,IAAA,mBAAa,EAAC,GAAG,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED,SAAgB,2BAA2B,CAAC,GAAY;IACpD,MAAM,OAAO,GAAG,IAAA,mBAAa,EAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,sBAAe,CAAC,oDAAoD,CAAC,CAAC;IACpF,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/request/permission/index.ts"],"names":[],"mappings":"AAOA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024.
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./helper"), exports);
|
|
24
|
+
__exportStar(require("./module"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/request/permission/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,2CAAyB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PermissionChecker, PermissionCheckerCheckContext } from '@authup/kit';
|
|
2
|
+
import type { Request } from 'routup';
|
|
3
|
+
export declare class RequestPermissionChecker {
|
|
4
|
+
protected req: Request;
|
|
5
|
+
protected checker: PermissionChecker;
|
|
6
|
+
constructor(req: Request, checker: PermissionChecker);
|
|
7
|
+
check(ctx: PermissionCheckerCheckContext): Promise<void>;
|
|
8
|
+
preCheck(ctx: PermissionCheckerCheckContext): Promise<void>;
|
|
9
|
+
preCheckOneOf(ctx: PermissionCheckerCheckContext): Promise<void>;
|
|
10
|
+
checkOneOf(ctx: PermissionCheckerCheckContext): Promise<void>;
|
|
11
|
+
protected extendCheckContext(ctx: PermissionCheckerCheckContext): PermissionCheckerCheckContext;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/request/permission/module.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,iBAAiB,EACjB,6BAA6B,EAChC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAItC,qBAAa,wBAAwB;IACjC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC;IAEvB,SAAS,CAAC,OAAO,EAAE,iBAAiB,CAAC;gBAEzB,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB;IAO9C,KAAK,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAIzD,QAAQ,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAM5D,aAAa,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAMpE,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,6BAA6B;CAWlE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024.
|
|
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.RequestPermissionChecker = void 0;
|
|
10
|
+
const core_kit_1 = require("@authup/core-kit");
|
|
11
|
+
const env_1 = require("../env");
|
|
12
|
+
const identity_1 = require("../identity");
|
|
13
|
+
class RequestPermissionChecker {
|
|
14
|
+
req;
|
|
15
|
+
checker;
|
|
16
|
+
constructor(req, checker) {
|
|
17
|
+
this.req = req;
|
|
18
|
+
this.checker = checker;
|
|
19
|
+
}
|
|
20
|
+
// --------------------------------------------------------------
|
|
21
|
+
async check(ctx) {
|
|
22
|
+
return this.checker.check(this.extendCheckContext(ctx));
|
|
23
|
+
}
|
|
24
|
+
async preCheck(ctx) {
|
|
25
|
+
return this.checker.preCheck(this.extendCheckContext(ctx));
|
|
26
|
+
}
|
|
27
|
+
// --------------------------------------------------------------
|
|
28
|
+
async preCheckOneOf(ctx) {
|
|
29
|
+
return this.checker.preCheckOneOf(this.extendCheckContext(ctx));
|
|
30
|
+
}
|
|
31
|
+
async checkOneOf(ctx) {
|
|
32
|
+
return this.checker.checkOneOf(this.extendCheckContext(ctx));
|
|
33
|
+
}
|
|
34
|
+
// --------------------------------------------------------------
|
|
35
|
+
extendCheckContext(ctx) {
|
|
36
|
+
const scopes = (0, env_1.useRequestEnv)(this.req, 'scopes') || [];
|
|
37
|
+
if (scopes.indexOf(core_kit_1.ScopeName.GLOBAL) !== -1) {
|
|
38
|
+
ctx.data = {
|
|
39
|
+
...ctx.data || {},
|
|
40
|
+
identity: (0, identity_1.useRequestIdentity)(this.req),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return ctx;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.RequestPermissionChecker = RequestPermissionChecker;
|
|
47
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/request/permission/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAA6C;AAM7C,gCAAuC;AACvC,0CAAiD;AAEjD,MAAa,wBAAwB;IACvB,GAAG,CAAU;IAEb,OAAO,CAAoB;IAErC,YAAY,GAAY,EAAE,OAA0B;QAChD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,iEAAiE;IAEjE,KAAK,CAAC,KAAK,CAAC,GAAkC;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAkC;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,iEAAiE;IAEjE,KAAK,CAAC,aAAa,CAAC,GAAkC;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAkC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,iEAAiE;IAEvD,kBAAkB,CAAC,GAAkC;QAC3D,MAAM,MAAM,GAAG,IAAA,mBAAa,EAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvD,IAAI,MAAM,CAAC,OAAO,CAAC,oBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1C,GAAG,CAAC,IAAI,GAAG;gBACP,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE;gBACjB,QAAQ,EAAE,IAAA,6BAAkB,EAAC,IAAI,CAAC,GAAG,CAAC;aACzC,CAAC;QACN,CAAC;QAED,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AA3CD,4DA2CC"}
|
package/dist/request/types.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestPermissionChecker } from './permission';
|
|
2
|
+
export type RequestIdentity = {
|
|
3
|
+
id: string;
|
|
4
|
+
type: 'user' | 'client' | 'robot';
|
|
5
|
+
realmId: string;
|
|
6
|
+
realmName: string;
|
|
7
|
+
attributes?: Record<string, any>;
|
|
8
|
+
};
|
|
2
9
|
export type RequestEnv = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
realm?: {
|
|
7
|
-
id?: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
};
|
|
10
|
-
userId?: string;
|
|
11
|
-
userName?: string;
|
|
12
|
-
robotId?: string;
|
|
13
|
-
robotName?: string;
|
|
10
|
+
permissionChecker?: RequestPermissionChecker;
|
|
11
|
+
identity?: RequestIdentity;
|
|
12
|
+
scopes?: string[];
|
|
14
13
|
};
|
|
15
14
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/request/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/request/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAE7C,QAAQ,CAAC,EAAE,eAAe,CAAC;IAE3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.mountAuthupMiddleware = mountAuthupMiddleware;
|
|
10
|
-
const
|
|
10
|
+
const server_adapter_http_1 = require("@authup/server-adapter-http");
|
|
11
11
|
const cookie_1 = require("@routup/basic/cookie");
|
|
12
12
|
const hapic_1 = require("hapic");
|
|
13
13
|
const routup_1 = require("routup");
|
|
@@ -72,7 +72,7 @@ function mountAuthupMiddleware(router, options) {
|
|
|
72
72
|
client: options.redisClient,
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
const middleware = (0,
|
|
75
|
+
const middleware = (0, server_adapter_http_1.createMiddleware)({
|
|
76
76
|
tokenByCookie: (req, cookieName) => (0, cookie_1.useRequestCookie)(req, cookieName),
|
|
77
77
|
tokenVerifier: {
|
|
78
78
|
baseURL: options.client.getBaseURL(),
|
|
@@ -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":";AAAA;;;;;GAKG;;AAYH,sDA4FC;AApGD,qEAA+D;AAC/D,iDAAwD;AACxD,iCAAiD;AAEjD,mCAAuD;AAEvD,mCAAsF;AAEtF,SAAgB,qBAAqB,CACjC,MAAc,EACd,OAA4C;IAE5C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,IAAA,uCAA+B,GAAE,CAAC;QAE/C,MAAM,CAAC,GAAG,CAAC,IAAA,oBAAW,EAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACtC,IAAA,kCAA0B,EAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAC7D,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC,CAAC;QAEJ,OAAO;IACX,CAA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-
|
|
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;AAExE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGtC,KAAK,4BAA4B,GAAG,IAAI,CACxC,qBAAqB,EACrB,aAAa,GACb,UAAU,GACV,YAAY,GACZ,KAAK,GACL,UAAU,GACV,UAAU,GACV,OAAO,CACN,CAAC;AAWF,wBAAgB,+BAA+B,IAAI,4BAA4B,CAW9E;AAED,wBAAgB,0BAA0B,CACtC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,4BAA4B,EAClC,aAAa,CAAC,EAAE,OAAO,QA2B1B"}
|
|
@@ -38,25 +38,21 @@ function applyTokenVerificationData(req, data, fakeAbilities) {
|
|
|
38
38
|
else {
|
|
39
39
|
abilities = data.permissions;
|
|
40
40
|
}
|
|
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,
|
|
41
|
+
const permissionChecker = new kit_1.PermissionChecker({
|
|
42
|
+
provider: new kit_1.PermissionMemoryProvider(abilities),
|
|
48
43
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
44
|
+
const requestPermissionChecker = new request_1.RequestPermissionChecker(req, permissionChecker);
|
|
45
|
+
(0, request_1.setRequestEnv)(req, 'permissionChecker', requestPermissionChecker);
|
|
46
|
+
(0, request_1.setRequestEnv)(req, 'identity', {
|
|
47
|
+
id: data.sub,
|
|
48
|
+
type: data.sub_kind,
|
|
49
|
+
realmId: data.realm_id,
|
|
50
|
+
realmName: data.realm_name,
|
|
51
|
+
attributes: {
|
|
52
|
+
id: data.sub,
|
|
53
|
+
name: data.sub_name,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
(0, request_1.setRequestEnv)(req, 'scopes', (0, core_kit_1.transformOAuth2ScopeToArray)(data.scope));
|
|
61
57
|
}
|
|
62
58
|
//# 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;;AA8BH,0EAWC;AAED,gEA8BC;AAtED,qCAA0E;AAC1E,+CAA0H;AAE1H,yCAAiD;AAEjD,2CAAwE;AAaxE,SAAS,iBAAiB;IACtB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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.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": {
|
|
@@ -11,14 +11,14 @@
|
|
|
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/kit": "^1.0.0-beta.
|
|
15
|
-
"@authup/core-kit": "^1.0.0-beta.
|
|
16
|
-
"@authup/core-http-kit": "^1.0.0-beta.
|
|
17
|
-
"@authup/server-
|
|
18
|
-
"@authup/server-
|
|
14
|
+
"@authup/kit": "^1.0.0-beta.22",
|
|
15
|
+
"@authup/core-kit": "^1.0.0-beta.22",
|
|
16
|
+
"@authup/core-http-kit": "^1.0.0-beta.22",
|
|
17
|
+
"@authup/server-adapter-kit": "^1.0.0-beta.20",
|
|
18
|
+
"@authup/server-adapter-http": "^1.0.0-beta.20",
|
|
19
19
|
"@ebec/http": "^2.3.0",
|
|
20
|
-
"@privateaim/kit": "^0.8.
|
|
21
|
-
"@privateaim/server-kit": "^0.8.
|
|
20
|
+
"@privateaim/kit": "^0.8.4",
|
|
21
|
+
"@privateaim/server-kit": "^0.8.4",
|
|
22
22
|
"@routup/basic": "^1.4.1",
|
|
23
23
|
"@routup/decorators": "^3.4.1",
|
|
24
24
|
"@routup/prometheus": "^2.4.0",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
"@routup/swagger": "^2.4.1",
|
|
27
27
|
"cors": "^2.8.5",
|
|
28
28
|
"hapic": "^2.5.1",
|
|
29
|
-
"locter": "^2.1.
|
|
29
|
+
"locter": "^2.1.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/cors": "^2.8.17",
|
|
33
33
|
"express-validator": "^7.2.0",
|
|
34
34
|
"redis-extension": "^1.5.0",
|
|
35
35
|
"routup": "^4.0.1",
|
|
36
|
-
"typeorm-extension": "^3.6.
|
|
36
|
+
"typeorm-extension": "^3.6.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"express-validator": "^7.2.0",
|
|
40
40
|
"redis-extension": "^1.5.0",
|
|
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",
|
package/src/middlewares/error.ts
CHANGED
|
@@ -5,13 +5,44 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { BuiltInPolicyType, PermissionError } from '@authup/kit';
|
|
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';
|
|
12
14
|
|
|
13
15
|
export function mountErrorMiddleware(router: Router) {
|
|
14
16
|
router.use(errorHandler((error, req, res) => {
|
|
17
|
+
const isServerError = error.statusCode >= 500 &&
|
|
18
|
+
error.statusCode < 600;
|
|
19
|
+
|
|
20
|
+
if (isServerError || error.logMessage) {
|
|
21
|
+
useLogger().error(error);
|
|
22
|
+
|
|
23
|
+
if (error.cause) {
|
|
24
|
+
useLogger().error(error.cause);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (error.cause instanceof PermissionError) {
|
|
29
|
+
error.expose = true;
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
error.cause.policy &&
|
|
33
|
+
error.cause.policy.type === BuiltInPolicyType.IDENTITY
|
|
34
|
+
) {
|
|
35
|
+
error.statusCode = 401;
|
|
36
|
+
} else {
|
|
37
|
+
error.statusCode = 403;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (error.cause instanceof EntityRelationLookupError) {
|
|
42
|
+
error.expose = true;
|
|
43
|
+
error.statusCode = 400;
|
|
44
|
+
}
|
|
45
|
+
|
|
15
46
|
// catch and decorate some db errors :)
|
|
16
47
|
switch (error.code) {
|
|
17
48
|
case 'ER_DUP_ENTRY':
|
|
@@ -28,18 +59,11 @@ export function mountErrorMiddleware(router: Router) {
|
|
|
28
59
|
break;
|
|
29
60
|
}
|
|
30
61
|
|
|
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
|
-
}
|
|
62
|
+
const exposeError = typeof error.expose === 'boolean' ?
|
|
63
|
+
error.expose :
|
|
64
|
+
!isServerError;
|
|
41
65
|
|
|
42
|
-
if (
|
|
66
|
+
if (!exposeError) {
|
|
43
67
|
error.message = 'An internal server error occurred.';
|
|
44
68
|
}
|
|
45
69
|
|
|
@@ -49,7 +73,7 @@ export function mountErrorMiddleware(router: Router) {
|
|
|
49
73
|
statusCode: error.statusCode,
|
|
50
74
|
code: `${error.code}`,
|
|
51
75
|
message: error.message,
|
|
52
|
-
...(isObject(error.data)
|
|
76
|
+
...(exposeError && isObject(error.data) ? error.data : {}),
|
|
53
77
|
};
|
|
54
78
|
}));
|
|
55
79
|
}
|
|
@@ -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
|
+
}
|
|
@@ -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/kit';
|
|
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';
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
-
import { PermissionName as AuthupPermissionName, REALM_MASTER_NAME } from '@authup/core-kit';
|
|
11
|
-
import type { TokenVerificationData } from '@authup/server-
|
|
8
|
+
import type { PermissionItem } from '@authup/kit';
|
|
9
|
+
import { PermissionChecker, PermissionMemoryProvider } from '@authup/kit';
|
|
10
|
+
import { PermissionName as AuthupPermissionName, REALM_MASTER_NAME, transformOAuth2ScopeToArray } from '@authup/core-kit';
|
|
11
|
+
import type { TokenVerificationData } from '@authup/server-adapter-kit';
|
|
12
12
|
import { PermissionName } from '@privateaim/kit';
|
|
13
13
|
import type { Request } from 'routup';
|
|
14
|
-
import { setRequestEnv } from '../../request';
|
|
14
|
+
import { RequestPermissionChecker, setRequestEnv } from '../../request';
|
|
15
15
|
|
|
16
16
|
type TokenVerificationDataMinimal = Pick<
|
|
17
17
|
TokenVerificationData,
|
|
@@ -20,16 +20,17 @@ TokenVerificationData,
|
|
|
20
20
|
'realm_name' |
|
|
21
21
|
'sub' |
|
|
22
22
|
'sub_kind' |
|
|
23
|
-
'sub_name'
|
|
23
|
+
'sub_name' |
|
|
24
|
+
'scope'
|
|
24
25
|
>;
|
|
25
26
|
|
|
26
|
-
function generateAbilities():
|
|
27
|
+
function generateAbilities(): PermissionItem[] {
|
|
27
28
|
return Object.values({
|
|
28
29
|
...PermissionName,
|
|
29
30
|
...AuthupPermissionName,
|
|
30
31
|
}).map((name) => ({
|
|
31
32
|
name,
|
|
32
|
-
} satisfies
|
|
33
|
+
} satisfies PermissionItem));
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export function createFakeTokenVerificationData(): TokenVerificationDataMinimal {
|
|
@@ -50,33 +51,29 @@ export function applyTokenVerificationData(
|
|
|
50
51
|
data: TokenVerificationDataMinimal,
|
|
51
52
|
fakeAbilities?: boolean,
|
|
52
53
|
) {
|
|
53
|
-
let abilities:
|
|
54
|
+
let abilities: PermissionItem[];
|
|
54
55
|
if (fakeAbilities) {
|
|
55
56
|
abilities = generateAbilities();
|
|
56
57
|
} else {
|
|
57
58
|
abilities = data.permissions;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
const permissionChecker = new PermissionChecker({
|
|
62
|
+
provider: new PermissionMemoryProvider(abilities),
|
|
63
|
+
});
|
|
64
|
+
const requestPermissionChecker = new RequestPermissionChecker(req, permissionChecker);
|
|
65
|
+
setRequestEnv(req, 'permissionChecker', requestPermissionChecker);
|
|
62
66
|
|
|
63
|
-
setRequestEnv(req, '
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
setRequestEnv(req, 'identity', {
|
|
68
|
+
id: data.sub,
|
|
69
|
+
type: data.sub_kind,
|
|
70
|
+
realmId: data.realm_id,
|
|
71
|
+
realmName: data.realm_name,
|
|
72
|
+
attributes: {
|
|
73
|
+
id: data.sub,
|
|
74
|
+
name: data.sub_name,
|
|
75
|
+
},
|
|
68
76
|
});
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
case 'user': {
|
|
72
|
-
setRequestEnv(req, 'userId', data.sub);
|
|
73
|
-
setRequestEnv(req, 'userName', data.sub_name);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case 'robot': {
|
|
77
|
-
setRequestEnv(req, 'robotId', data.sub);
|
|
78
|
-
setRequestEnv(req, 'robotName', data.sub_name);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
78
|
+
setRequestEnv(req, 'scopes', transformOAuth2ScopeToArray(data.scope));
|
|
82
79
|
}
|