@thisisagile/easy-express 10.4.0 → 10.5.8
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.
|
@@ -8,13 +8,13 @@ const passport_1 = __importDefault(require("passport"));
|
|
|
8
8
|
const passport_jwt_1 = require("passport-jwt");
|
|
9
9
|
const AuthError_1 = require("./AuthError");
|
|
10
10
|
const easy_1 = require("@thisisagile/easy");
|
|
11
|
-
const checkLabCoat = () => (req, res, next) => next(easy_1.Environment.Dev.equals(easy_1.ctx.env.name)
|
|
11
|
+
const checkLabCoat = () => (req, res, next) => next((0, easy_1.ifFalse)(easy_1.Environment.Dev.equals(easy_1.ctx.env.name), (0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden)));
|
|
12
12
|
exports.checkLabCoat = checkLabCoat;
|
|
13
13
|
const checkToken = () => passport_1.default.authenticate('jwt', { session: false, failWithError: true });
|
|
14
14
|
exports.checkToken = checkToken;
|
|
15
|
-
const checkScope = (scope) => (req, res, next) => next(req.user?.scopes?.includes(scope.id)
|
|
15
|
+
const checkScope = (scope) => (req, res, next) => next((0, easy_1.ifFalse)(req.user?.scopes?.includes(scope.id), (0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden)));
|
|
16
16
|
exports.checkScope = checkScope;
|
|
17
|
-
const checkUseCase = (uc) => (req, res, next) => next(req.user?.usecases?.includes(uc.id)
|
|
17
|
+
const checkUseCase = (uc) => (req, res, next) => next((0, easy_1.ifFalse)(req.user?.usecases?.includes(uc.id), (0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden)));
|
|
18
18
|
exports.checkUseCase = checkUseCase;
|
|
19
19
|
const wrapSecretOrKeyProvider = (p) => p
|
|
20
20
|
? (request, rawJwtToken, done) => p(request, rawJwtToken)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityHandler.js","sourceRoot":"","sources":["../../src/express/SecurityHandler.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAChC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AAI,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,kBAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvB,OAAO,kBAAQ,CAAC,UAAU,EAAE,CAAC;AAC/B,CAAC,CAAC;AAnBW,QAAA,QAAQ,YAmBnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-express",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.5.8",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "10.
|
|
34
|
+
"@thisisagile/easy-test": "10.5.8",
|
|
35
35
|
"@types/cls-hooked": "^4.3.3",
|
|
36
36
|
"@types/form-urlencoded": "^4.4.0",
|
|
37
37
|
"@types/jsonwebtoken": "^8.5.8",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@types/validator": "^13.7.2"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@thisisagile/easy": "10.
|
|
44
|
+
"@thisisagile/easy": "10.5.8",
|
|
45
45
|
"@types/express": "^4.17.13",
|
|
46
46
|
"cls-hooked": "^4.2.2",
|
|
47
47
|
"express": "^4.17.3",
|
|
@@ -2,7 +2,7 @@ import express, { Request, RequestHandler } from 'express';
|
|
|
2
2
|
import passport from 'passport';
|
|
3
3
|
import passportJwt, { ExtractJwt, Strategy as JwtStrategy, StrategyOptions } from 'passport-jwt';
|
|
4
4
|
import { authError } from './AuthError';
|
|
5
|
-
import { ctx, Environment, HttpStatus, Scope, UseCase } from '@thisisagile/easy';
|
|
5
|
+
import { ctx, Environment, HttpStatus, ifFalse, Scope, UseCase } from '@thisisagile/easy';
|
|
6
6
|
|
|
7
7
|
type SecretOrKeyProvider = (request: Request, rawJwtToken: any) => Promise<string | Buffer>;
|
|
8
8
|
|
|
@@ -29,19 +29,19 @@ export interface SecurityOptions {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const checkLabCoat = (): RequestHandler => (req, res, next) =>
|
|
32
|
-
next(Environment.Dev.equals(ctx.env.name)
|
|
32
|
+
next(ifFalse(Environment.Dev.equals(ctx.env.name), authError(HttpStatus.Forbidden)));
|
|
33
33
|
|
|
34
34
|
export const checkToken = (): RequestHandler => passport.authenticate('jwt', { session: false, failWithError: true });
|
|
35
35
|
|
|
36
36
|
export const checkScope =
|
|
37
37
|
(scope: Scope): RequestHandler =>
|
|
38
38
|
(req, res, next) =>
|
|
39
|
-
next((req.user as any)?.scopes?.includes(scope.id)
|
|
39
|
+
next(ifFalse((req.user as any)?.scopes?.includes(scope.id), authError(HttpStatus.Forbidden)));
|
|
40
40
|
|
|
41
41
|
export const checkUseCase =
|
|
42
42
|
(uc: UseCase): RequestHandler =>
|
|
43
43
|
(req, res, next) =>
|
|
44
|
-
next((req.user as any)?.usecases?.includes(uc.id)
|
|
44
|
+
next(ifFalse((req.user as any)?.usecases?.includes(uc.id), authError(HttpStatus.Forbidden)));
|
|
45
45
|
|
|
46
46
|
const wrapSecretOrKeyProvider = (p?: SecretOrKeyProvider): passportJwt.SecretOrKeyProvider | undefined =>
|
|
47
47
|
p
|