@loopback/example-access-control-migration 7.1.1 → 7.1.3

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/application.js +3 -3
  3. package/dist/application.js.map +1 -1
  4. package/dist/controllers/user.controller.d.ts +1 -1
  5. package/dist/controllers/user.controller.js +3 -3
  6. package/dist/controllers/user.controller.js.map +1 -1
  7. package/package.json +18 -17
  8. package/src/application.ts +1 -1
  9. package/src/controllers/user.controller.ts +1 -1
  10. package/tsconfig.json +3 -0
  11. package/dist/components/jwt-authentication/index.d.ts +0 -3
  12. package/dist/components/jwt-authentication/index.js +0 -11
  13. package/dist/components/jwt-authentication/index.js.map +0 -1
  14. package/dist/components/jwt-authentication/jwt-authentication-component.d.ts +0 -5
  15. package/dist/components/jwt-authentication/jwt-authentication-component.js +0 -31
  16. package/dist/components/jwt-authentication/jwt-authentication-component.js.map +0 -1
  17. package/dist/components/jwt-authentication/keys.d.ts +0 -16
  18. package/dist/components/jwt-authentication/keys.js +0 -24
  19. package/dist/components/jwt-authentication/keys.js.map +0 -1
  20. package/dist/components/jwt-authentication/services/index.d.ts +0 -4
  21. package/dist/components/jwt-authentication/services/index.js +0 -12
  22. package/dist/components/jwt-authentication/services/index.js.map +0 -1
  23. package/dist/components/jwt-authentication/services/jwt.auth.strategy.d.ts +0 -11
  24. package/dist/components/jwt-authentication/services/jwt.auth.strategy.js +0 -44
  25. package/dist/components/jwt-authentication/services/jwt.auth.strategy.js.map +0 -1
  26. package/dist/components/jwt-authentication/services/jwt.service.d.ts +0 -9
  27. package/dist/components/jwt-authentication/services/jwt.service.js +0 -70
  28. package/dist/components/jwt-authentication/services/jwt.service.js.map +0 -1
  29. package/dist/components/jwt-authentication/services/security.spec.d.ts +0 -8
  30. package/dist/components/jwt-authentication/services/security.spec.js +0 -16
  31. package/dist/components/jwt-authentication/services/security.spec.js.map +0 -1
  32. package/dist/components/jwt-authentication/services/user.service.d.ts +0 -18
  33. package/dist/components/jwt-authentication/services/user.service.js +0 -50
  34. package/dist/components/jwt-authentication/services/user.service.js.map +0 -1
  35. package/src/components/jwt-authentication/index.ts +0 -8
  36. package/src/components/jwt-authentication/jwt-authentication-component.ts +0 -37
  37. package/src/components/jwt-authentication/keys.ts +0 -34
  38. package/src/components/jwt-authentication/services/index.ts +0 -9
  39. package/src/components/jwt-authentication/services/jwt.auth.strategy.ts +0 -50
  40. package/src/components/jwt-authentication/services/jwt.service.ts +0 -77
  41. package/src/components/jwt-authentication/services/security.spec.ts +0 -18
  42. package/src/components/jwt-authentication/services/user.service.ts +0 -65
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.1.3](https://github.com/loopbackio/loopback-next/compare/@loopback/example-access-control-migration@7.1.2...@loopback/example-access-control-migration@7.1.3) (2025-03-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * replace custom authentication-jwt component with @loopback/authentication-jwt ([f3d483c](https://github.com/loopbackio/loopback-next/commit/f3d483cac55f64ef2c717e3c6033c55e2f0152cd))
12
+
13
+
14
+
15
+
16
+
17
+ ## [7.1.2](https://github.com/loopbackio/loopback-next/compare/@loopback/example-access-control-migration@7.1.1...@loopback/example-access-control-migration@7.1.2) (2025-02-13)
18
+
19
+ **Note:** Version bump only for package @loopback/example-access-control-migration
20
+
21
+
22
+
23
+
24
+
6
25
  ## [7.1.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-access-control-migration@7.1.0...@loopback/example-access-control-migration@7.1.1) (2025-01-15)
7
26
 
8
27
  **Note:** Version bump only for package @loopback/example-access-control-migration
@@ -16,7 +16,7 @@ const rest_explorer_1 = require("@loopback/rest-explorer");
16
16
  const service_proxy_1 = require("@loopback/service-proxy");
17
17
  const path_1 = tslib_1.__importDefault(require("path"));
18
18
  const casbin_authorization_1 = require("./components/casbin-authorization");
19
- const jwt_authentication_1 = require("./components/jwt-authentication");
19
+ const authentication_jwt_1 = require("@loopback/authentication-jwt");
20
20
  const sequence_1 = require("./sequence");
21
21
  exports.PackageKey = core_1.BindingKey.create('application.package');
22
22
  class AccessControlApplication extends (0, boot_1.BootMixin)((0, service_proxy_1.ServiceMixin)((0, repository_1.RepositoryMixin)(rest_1.RestApplication))) {
@@ -31,7 +31,7 @@ class AccessControlApplication extends (0, boot_1.BootMixin)((0, service_proxy_1
31
31
  // Bind authentication and authorization related elements
32
32
  this.component(authentication_1.AuthenticationComponent);
33
33
  this.component(authorization_1.AuthorizationComponent);
34
- this.component(jwt_authentication_1.JWTAuthenticationComponent);
34
+ this.component(authentication_jwt_1.JWTAuthenticationComponent);
35
35
  this.component(casbin_authorization_1.CasbinAuthorizationComponent);
36
36
  this.projectRoot = __dirname;
37
37
  // Customize @loopback/boot Booter Conventions here
@@ -52,7 +52,7 @@ class AccessControlApplication extends (0, boot_1.BootMixin)((0, service_proxy_1
52
52
  version: require('.././package.json').version,
53
53
  },
54
54
  paths: {},
55
- components: { securitySchemes: jwt_authentication_1.SECURITY_SCHEME_SPEC },
55
+ components: { securitySchemes: authentication_jwt_1.SECURITY_SCHEME_SPEC },
56
56
  security: [
57
57
  {
58
58
  jwt: [],
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,6DAAiE;AACjE,2DAA+D;AAC/D,yCAAyC;AACzC,yCAA6D;AAC7D,qDAAqD;AACrD,yCAA+C;AAC/C,2DAA8D;AAC9D,2DAAqD;AACrD,wDAAwB;AACxB,4EAA+E;AAC/E,wEAGyC;AACzC,yCAAsC;AAYzB,QAAA,UAAU,GAAG,iBAAU,CAAC,MAAM,CAAc,qBAAqB,CAAC,CAAC;AAEhF,MAAa,wBAAyB,S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gBACX,8CAA8C;gBAC9C,IAAI,EAAE,CAAC,aAAa,CAAC;gBACrB,UAAU,EAAE,CAAC,gBAAgB,CAAC;gBAC9B,MAAM,EAAE,IAAI;aACb;SACF,CAAC;IACJ,CAAC;IAED,eAAe;QACb,IAAI,CAAC,GAAG,CAAC;YACP,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE;gBACJ,KAAK,EAAE,wBAAwB;gBAC/B,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO;aAC9C;YACD,KAAK,EAAE,EAAE;YACT,UAAU,EAAE,EAAC,eAAe,EAAE,yCAAoB,EAAC;YACnD,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,EAAE;iBACR;aACF;YACD,OAAO,EAAE,CAAC,EAAC,GAAG,EAAE,GAAG,EAAC,CAAC;SACtB,CAAC,CAAC;IACL,CAAC;CACF;AAlDD,4DAkDC"}
@@ -1,6 +1,6 @@
1
1
  import { TokenService, UserService } from '@loopback/authentication';
2
2
  import { SchemaObject } from '@loopback/rest';
3
- import { Credentials } from '../components/jwt-authentication';
3
+ import { Credentials } from '@loopback/authentication-jwt';
4
4
  import { User } from '../models';
5
5
  export declare const CredentialsRequestBody: {
6
6
  description: string;
@@ -8,7 +8,7 @@ exports.UserController = exports.CredentialsRequestBody = void 0;
8
8
  const tslib_1 = require("tslib");
9
9
  const core_1 = require("@loopback/core");
10
10
  const rest_1 = require("@loopback/rest");
11
- const jwt_authentication_1 = require("../components/jwt-authentication");
11
+ const authentication_jwt_1 = require("@loopback/authentication-jwt");
12
12
  const CredentialsSchema = {
13
13
  type: 'object',
14
14
  required: ['email', 'password'],
@@ -72,8 +72,8 @@ tslib_1.__decorate([
72
72
  tslib_1.__metadata("design:returntype", Promise)
73
73
  ], UserController.prototype, "login", null);
74
74
  exports.UserController = UserController = tslib_1.__decorate([
75
- tslib_1.__param(0, (0, core_1.inject)(jwt_authentication_1.TokenServiceBindings.TOKEN_SERVICE)),
76
- tslib_1.__param(1, (0, core_1.inject)(jwt_authentication_1.UserServiceBindings.USER_SERVICE)),
75
+ tslib_1.__param(0, (0, core_1.inject)(authentication_jwt_1.TokenServiceBindings.TOKEN_SERVICE)),
76
+ tslib_1.__param(1, (0, core_1.inject)(authentication_jwt_1.UserServiceBindings.USER_SERVICE)),
77
77
  tslib_1.__metadata("design:paramtypes", [Object, Object])
78
78
  ], UserController);
79
79
  //# sourceMappingURL=user.controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.controller.js","sourceRoot":"","sources":["../../src/controllers/user.controller.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;;AAKhE,yCAAsC;AACtC,yCAA+D;AAC/D,yEAI0C;AAG1C,MAAM,iBAAiB,GAAiB;IACtC,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;IAC/B,UAAU,EAAE;QACV,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;SAChB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,CAAC;SACb;KACF;CACF,CAAC;AAEW,QAAA,sBAAsB,GAAG;IACpC,WAAW,EAAE,6BAA6B;IAC1C,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE;QACP,kBAAkB,EAAE,EAAC,MAAM,EAAE,iBAAiB,EAAC;KAChD;CACF,CAAC;AAEF,IAAa,cAAc,GAA3B,MAAa,cAAc;IACzB,YAES,UAAwB,EAExB,WAA2C;QAF3C,eAAU,GAAV,UAAU,CAAc;QAExB,gBAAW,GAAX,WAAW,CAAgC;IACjD,CAAC;IAqBE,AAAN,KAAK,CAAC,KAAK,CAC4B,WAAwB;QAE7D,sDAAsD;QACtD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAEnE,8EAA8E;QAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;QAEhE,oDAAoD;QACpD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAE/D,OAAO,EAAC,KAAK,EAAC,CAAC;IACjB,CAAC;CACF,CAAA;AAzCY,wCAAc;AA2BnB;IAnBL,IAAA,WAAI,EAAC,cAAc,EAAE;QACpB,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,WAAW,EAAE,OAAO;gBACpB,OAAO,EAAE;oBACP,kBAAkB,EAAE;wBAClB,MAAM,EAAE;4BACN,IAAI,EAAE,QAAQ;4BACd,UAAU,EAAE;gCACV,KAAK,EAAE;oCACL,IAAI,EAAE,QAAQ;iCACf;6BACF;yBACF;qBACF;iBACF;aACF;SACF;KACF,CAAC;IAEC,mBAAA,IAAA,kBAAW,EAAC,8BAAsB,CAAC,CAAA;;;;2CAYrC;yBAxCU,cAAc;IAEtB,mBAAA,IAAA,aAAM,EAAC,yCAAoB,CAAC,aAAa,CAAC,CAAA;IAE1C,mBAAA,IAAA,aAAM,EAAC,wCAAmB,CAAC,YAAY,CAAC,CAAA;;GAJhC,cAAc,CAyC1B"}
1
+ {"version":3,"file":"user.controller.js","sourceRoot":"","sources":["../../src/controllers/user.controller.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;;AAKhE,yCAAsC;AACtC,yCAA+D;AAC/D,qEAIsC;AAGtC,MAAM,iBAAiB,GAAiB;IACtC,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;IAC/B,UAAU,EAAE;QACV,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;SAChB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,CAAC;SACb;KACF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,YAAY,CAAC,CAAA;;GAJhC,cAAc,CAyC1B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loopback/example-access-control-migration",
3
3
  "description": "Tutorial example on how to migrate the access control example with LoopBack 4.",
4
- "version": "7.1.1",
4
+ "version": "7.1.3",
5
5
  "keywords": [
6
6
  "loopback",
7
7
  "LoopBack",
@@ -51,31 +51,32 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@loopback/authentication": "^11.0.10",
55
- "@loopback/authorization": "^0.15.10",
56
- "@loopback/boot": "^7.0.10",
57
- "@loopback/core": "^6.1.7",
58
- "@loopback/repository": "^7.0.10",
59
- "@loopback/rest": "^14.0.10",
60
- "@loopback/rest-explorer": "^7.0.10",
61
- "@loopback/security": "^0.11.10",
62
- "@loopback/service-proxy": "^7.0.10",
54
+ "@loopback/authentication": "^11.0.12",
55
+ "@loopback/authentication-jwt": "^0.15.12",
56
+ "@loopback/authorization": "^0.15.12",
57
+ "@loopback/boot": "^7.0.12",
58
+ "@loopback/core": "^6.1.9",
59
+ "@loopback/repository": "^7.0.12",
60
+ "@loopback/rest": "^14.0.12",
61
+ "@loopback/rest-explorer": "^7.0.12",
62
+ "@loopback/security": "^0.11.12",
63
+ "@loopback/service-proxy": "^7.0.12",
63
64
  "@types/bcryptjs": "2.4.6",
64
65
  "bcryptjs": "^2.4.3",
65
- "casbin": "^5.37.0",
66
+ "casbin": "^5.38.0",
66
67
  "jsonwebtoken": "^9.0.2",
67
68
  "loopback-connector-rest": "^5.0.2"
68
69
  },
69
70
  "devDependencies": {
70
- "@loopback/build": "^11.0.9",
71
+ "@loopback/build": "^11.0.10",
71
72
  "@loopback/eslint-config": "^15.0.5",
72
- "@loopback/http-caching-proxy": "^6.0.10",
73
- "@loopback/testlab": "^7.0.9",
74
- "@types/lodash": "^4.17.14",
75
- "@types/node": "^16.18.123",
73
+ "@loopback/http-caching-proxy": "^6.0.12",
74
+ "@loopback/testlab": "^7.0.11",
75
+ "@types/lodash": "^4.17.16",
76
+ "@types/node": "^16.18.126",
76
77
  "eslint": "^8.57.1",
77
78
  "lodash": "^4.17.21",
78
79
  "typescript": "~5.2.2"
79
80
  },
80
- "gitHead": "92fee0f161ccc2bb9d28579450f98fc43c959416"
81
+ "gitHead": "0c7708d49efe343cd46350e5014a147c920e59f7"
81
82
  }
@@ -16,7 +16,7 @@ import {CasbinAuthorizationComponent} from './components/casbin-authorization';
16
16
  import {
17
17
  JWTAuthenticationComponent,
18
18
  SECURITY_SCHEME_SPEC,
19
- } from './components/jwt-authentication';
19
+ } from '@loopback/authentication-jwt';
20
20
  import {MySequence} from './sequence';
21
21
 
22
22
  export {ApplicationConfig};
@@ -12,7 +12,7 @@ import {
12
12
  Credentials,
13
13
  TokenServiceBindings,
14
14
  UserServiceBindings,
15
- } from '../components/jwt-authentication';
15
+ } from '@loopback/authentication-jwt';
16
16
  import {User} from '../models';
17
17
 
18
18
  const CredentialsSchema: SchemaObject = {
package/tsconfig.json CHANGED
@@ -11,6 +11,9 @@
11
11
  "src/**/*.json"
12
12
  ],
13
13
  "references": [
14
+ {
15
+ "path": "../../extensions/authentication-jwt/tsconfig.json"
16
+ },
14
17
  {
15
18
  "path": "../../packages/authentication/tsconfig.json"
16
19
  },
@@ -1,3 +0,0 @@
1
- export * from './jwt-authentication-component';
2
- export * from './keys';
3
- export * from './services';
@@ -1,11 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const tslib_1 = require("tslib");
8
- tslib_1.__exportStar(require("./jwt-authentication-component"), exports);
9
- tslib_1.__exportStar(require("./keys"), exports);
10
- tslib_1.__exportStar(require("./services"), exports);
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/jwt-authentication/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yEAA+C;AAC/C,iDAAuB;AACvB,qDAA2B"}
@@ -1,5 +0,0 @@
1
- import { Application, Binding, Component } from '@loopback/core';
2
- export declare class JWTAuthenticationComponent implements Component {
3
- bindings: Binding[];
4
- constructor(app: Application);
5
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.JWTAuthenticationComponent = void 0;
8
- const tslib_1 = require("tslib");
9
- const authentication_1 = require("@loopback/authentication");
10
- const core_1 = require("@loopback/core");
11
- const keys_1 = require("./keys");
12
- const jwt_auth_strategy_1 = require("./services/jwt.auth.strategy");
13
- const jwt_service_1 = require("./services/jwt.service");
14
- const user_service_1 = require("./services/user.service");
15
- let JWTAuthenticationComponent = class JWTAuthenticationComponent {
16
- constructor(app) {
17
- this.bindings = [
18
- core_1.Binding.bind(keys_1.TokenServiceBindings.TOKEN_SECRET).to(keys_1.TokenServiceConstants.TOKEN_SECRET_VALUE),
19
- core_1.Binding.bind(keys_1.TokenServiceBindings.TOKEN_EXPIRES_IN).to(keys_1.TokenServiceConstants.TOKEN_EXPIRES_IN_VALUE),
20
- core_1.Binding.bind(keys_1.TokenServiceBindings.TOKEN_SERVICE).toClass(jwt_service_1.JWTService),
21
- core_1.Binding.bind(keys_1.UserServiceBindings.USER_SERVICE).toClass(user_service_1.MyUserService),
22
- ];
23
- (0, authentication_1.registerAuthenticationStrategy)(app, jwt_auth_strategy_1.JWTAuthenticationStrategy);
24
- }
25
- };
26
- exports.JWTAuthenticationComponent = JWTAuthenticationComponent;
27
- exports.JWTAuthenticationComponent = JWTAuthenticationComponent = tslib_1.__decorate([
28
- tslib_1.__param(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
29
- tslib_1.__metadata("design:paramtypes", [core_1.Application])
30
- ], JWTAuthenticationComponent);
31
- //# sourceMappingURL=jwt-authentication-component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt-authentication-component.js","sourceRoot":"","sources":["../../../src/components/jwt-authentication/jwt-authentication-component.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,6DAAwE;AACxE,yCAMwB;AACxB,iCAIgB;AAChB,oEAAuE;AACvE,wDAAkD;AAClD,0DAAsD;AAEtD,IAAa,0BAA0B,GAAvC,MAAa,0BAA0B;IAWrC,YAAuD,GAAgB;QAVvE,aAAQ,GAAc;YACpB,cAAO,CAAC,IAAI,CAAC,2BAAoB,CAAC,YAAY,CAAC,CAAC,EAAE,CAChD,4BAAqB,CAAC,kBAAkB,CACzC;YACD,cAAO,CAAC,IAAI,CAAC,2BAAoB,CAAC,gBAAgB,CAAC,CAAC,EAAE,CACpD,4BAAqB,CAAC,sBAAsB,CAC7C;YACD,cAAO,CAAC,IAAI,CAAC,2BAAoB,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,wBAAU,CAAC;YACpE,cAAO,CAAC,IAAI,CAAC,0BAAmB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,4BAAa,CAAC;SACtE,CAAC;QAEA,IAAA,+CAA8B,EAAC,GAAG,EAAE,6CAAyB,CAAC,CAAC;IACjE,CAAC;CACF,CAAA;AAdY,gEAA0B;qCAA1B,0BAA0B;IAWxB,mBAAA,IAAA,aAAM,EAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;6CAAM,kBAAW;GAX5D,0BAA0B,CActC"}
@@ -1,16 +0,0 @@
1
- import { TokenService, UserService } from '@loopback/authentication';
2
- import { BindingKey } from '@loopback/core';
3
- import { User } from '../../models/user.model';
4
- import { Credentials } from './services/user.service';
5
- export declare namespace TokenServiceConstants {
6
- const TOKEN_SECRET_VALUE = "myjwts3cr3t";
7
- const TOKEN_EXPIRES_IN_VALUE = "21600";
8
- }
9
- export declare namespace TokenServiceBindings {
10
- const TOKEN_SECRET: BindingKey<string>;
11
- const TOKEN_EXPIRES_IN: BindingKey<string>;
12
- const TOKEN_SERVICE: BindingKey<TokenService>;
13
- }
14
- export declare namespace UserServiceBindings {
15
- const USER_SERVICE: BindingKey<UserService<User, Credentials>>;
16
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.UserServiceBindings = exports.TokenServiceBindings = exports.TokenServiceConstants = void 0;
8
- const core_1 = require("@loopback/core");
9
- var TokenServiceConstants;
10
- (function (TokenServiceConstants) {
11
- TokenServiceConstants.TOKEN_SECRET_VALUE = 'myjwts3cr3t';
12
- TokenServiceConstants.TOKEN_EXPIRES_IN_VALUE = '21600';
13
- })(TokenServiceConstants || (exports.TokenServiceConstants = TokenServiceConstants = {}));
14
- var TokenServiceBindings;
15
- (function (TokenServiceBindings) {
16
- TokenServiceBindings.TOKEN_SECRET = core_1.BindingKey.create('authentication.jwt.secret');
17
- TokenServiceBindings.TOKEN_EXPIRES_IN = core_1.BindingKey.create('authentication.jwt.expires.in.seconds');
18
- TokenServiceBindings.TOKEN_SERVICE = core_1.BindingKey.create('services.authentication.jwt.tokenservice');
19
- })(TokenServiceBindings || (exports.TokenServiceBindings = TokenServiceBindings = {}));
20
- var UserServiceBindings;
21
- (function (UserServiceBindings) {
22
- UserServiceBindings.USER_SERVICE = core_1.BindingKey.create('services.user.service');
23
- })(UserServiceBindings || (exports.UserServiceBindings = UserServiceBindings = {}));
24
- //# sourceMappingURL=keys.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/components/jwt-authentication/keys.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;AAGhE,yCAA0C;AAM1C,IAAiB,qBAAqB,CAGrC;AAHD,WAAiB,qBAAqB;IACvB,wCAAkB,GAAG,aAAa,CAAC;IACnC,4CAAsB,GAAG,OAAO,CAAC;AAChD,CAAC,EAHgB,qBAAqB,qCAArB,qBAAqB,QAGrC;AAED,IAAiB,oBAAoB,CAUpC;AAVD,WAAiB,oBAAoB;IACtB,iCAAY,GAAG,iBAAU,CAAC,MAAM,CAC3C,2BAA2B,CAC5B,CAAC;IACW,qCAAgB,GAAG,iBAAU,CAAC,MAAM,CAC/C,uCAAuC,CACxC,CAAC;IACW,kCAAa,GAAG,iBAAU,CAAC,MAAM,CAC5C,0CAA0C,CAC3C,CAAC;AACJ,CAAC,EAVgB,oBAAoB,oCAApB,oBAAoB,QAUpC;AAED,IAAiB,mBAAmB,CAInC;AAJD,WAAiB,mBAAmB;IACrB,gCAAY,GAAG,iBAAU,CAAC,MAAM,CAC3C,uBAAuB,CACxB,CAAC;AACJ,CAAC,EAJgB,mBAAmB,mCAAnB,mBAAmB,QAInC"}
@@ -1,4 +0,0 @@
1
- export * from './jwt.auth.strategy';
2
- export * from './jwt.service';
3
- export * from './security.spec';
4
- export * from './user.service';
@@ -1,12 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const tslib_1 = require("tslib");
8
- tslib_1.__exportStar(require("./jwt.auth.strategy"), exports);
9
- tslib_1.__exportStar(require("./jwt.service"), exports);
10
- tslib_1.__exportStar(require("./security.spec"), exports);
11
- tslib_1.__exportStar(require("./user.service"), exports);
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/jwt-authentication/services/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;AAEhE,8DAAoC;AACpC,wDAA8B;AAC9B,0DAAgC;AAChC,yDAA+B"}
@@ -1,11 +0,0 @@
1
- /// <reference types="express" />
2
- import { AuthenticationStrategy, TokenService } from '@loopback/authentication';
3
- import { Request } from '@loopback/rest';
4
- import { UserProfile } from '@loopback/security';
5
- export declare class JWTAuthenticationStrategy implements AuthenticationStrategy {
6
- tokenService: TokenService;
7
- name: string;
8
- constructor(tokenService: TokenService);
9
- authenticate(request: Request): Promise<UserProfile | undefined>;
10
- extractCredentials(request: Request): string;
11
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.JWTAuthenticationStrategy = void 0;
8
- const tslib_1 = require("tslib");
9
- const core_1 = require("@loopback/core");
10
- const rest_1 = require("@loopback/rest");
11
- const keys_1 = require("../keys");
12
- let JWTAuthenticationStrategy = class JWTAuthenticationStrategy {
13
- constructor(tokenService) {
14
- this.tokenService = tokenService;
15
- this.name = 'jwt';
16
- }
17
- async authenticate(request) {
18
- const token = this.extractCredentials(request);
19
- const userProfile = await this.tokenService.verifyToken(token);
20
- return userProfile;
21
- }
22
- extractCredentials(request) {
23
- if (!request.headers.authorization) {
24
- throw new rest_1.HttpErrors.Unauthorized(`Authorization header not found.`);
25
- }
26
- // for example : Bearer xxx.yyy.zzz
27
- const authHeaderValue = request.headers.authorization;
28
- if (!authHeaderValue.startsWith('Bearer')) {
29
- throw new rest_1.HttpErrors.Unauthorized(`Authorization header is not of type 'Bearer'.`);
30
- }
31
- //split the string into 2 parts : 'Bearer ' and the `xxx.yyy.zzz`
32
- const parts = authHeaderValue.split(' ');
33
- if (parts.length !== 2)
34
- throw new rest_1.HttpErrors.Unauthorized(`Authorization header value has too many parts. It must follow the pattern: 'Bearer xx.yy.zz' where xx.yy.zz is a valid JWT token.`);
35
- const token = parts[1];
36
- return token;
37
- }
38
- };
39
- exports.JWTAuthenticationStrategy = JWTAuthenticationStrategy;
40
- exports.JWTAuthenticationStrategy = JWTAuthenticationStrategy = tslib_1.__decorate([
41
- tslib_1.__param(0, (0, core_1.inject)(keys_1.TokenServiceBindings.TOKEN_SERVICE)),
42
- tslib_1.__metadata("design:paramtypes", [Object])
43
- ], JWTAuthenticationStrategy);
44
- //# sourceMappingURL=jwt.auth.strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.auth.strategy.js","sourceRoot":"","sources":["../../../../src/components/jwt-authentication/services/jwt.auth.strategy.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;;AAGhE,yCAAsC;AACtC,yCAAmD;AAEnD,kCAA6C;AAE7C,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAGpC,YAEE,YAAiC;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAJnC,SAAI,GAAG,KAAK,CAAC;IAKV,CAAC;IAEJ,KAAK,CAAC,YAAY,CAAC,OAAgB;QACjC,MAAM,KAAK,GAAW,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACvD,MAAM,WAAW,GAAgB,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5E,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,kBAAkB,CAAC,OAAgB;QACjC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE;YAClC,MAAM,IAAI,iBAAU,CAAC,YAAY,CAAC,iCAAiC,CAAC,CAAC;SACtE;QAED,mCAAmC;QACnC,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;QAEtD,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YACzC,MAAM,IAAI,iBAAU,CAAC,YAAY,CAC/B,+CAA+C,CAChD,CAAC;SACH;QAED,iEAAiE;QACjE,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YACpB,MAAM,IAAI,iBAAU,CAAC,YAAY,CAC/B,mIAAmI,CACpI,CAAC;QACJ,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAtCY,8DAAyB;oCAAzB,yBAAyB;IAIjC,mBAAA,IAAA,aAAM,EAAC,2BAAoB,CAAC,aAAa,CAAC,CAAA;;GAJlC,yBAAyB,CAsCrC"}
@@ -1,9 +0,0 @@
1
- import { TokenService } from '@loopback/authentication';
2
- import { UserProfile } from '@loopback/security';
3
- export declare class JWTService implements TokenService {
4
- private jwtSecret;
5
- private jwtExpiresIn;
6
- constructor(jwtSecret: string, jwtExpiresIn: string);
7
- verifyToken(token: string): Promise<UserProfile>;
8
- generateToken(userProfile: UserProfile): Promise<string>;
9
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.JWTService = void 0;
8
- const tslib_1 = require("tslib");
9
- const core_1 = require("@loopback/core");
10
- const rest_1 = require("@loopback/rest");
11
- const security_1 = require("@loopback/security");
12
- const util_1 = require("util");
13
- const keys_1 = require("../keys");
14
- const jwt = require('jsonwebtoken');
15
- const signAsync = (0, util_1.promisify)(jwt.sign);
16
- const verifyAsync = (0, util_1.promisify)(jwt.verify);
17
- let JWTService = class JWTService {
18
- constructor(jwtSecret, jwtExpiresIn) {
19
- this.jwtSecret = jwtSecret;
20
- this.jwtExpiresIn = jwtExpiresIn;
21
- }
22
- async verifyToken(token) {
23
- if (!token) {
24
- throw new rest_1.HttpErrors.Unauthorized(`Error verifying token : 'token' is null`);
25
- }
26
- let userProfile;
27
- try {
28
- // decode user profile from token
29
- const decodedToken = await verifyAsync(token, this.jwtSecret);
30
- // don't copy over token field 'iat' and 'exp', nor 'email' to user profile
31
- userProfile = Object.assign({ [security_1.securityId]: '', name: '' }, {
32
- [security_1.securityId]: decodedToken.id,
33
- name: decodedToken.name,
34
- id: decodedToken.id,
35
- });
36
- }
37
- catch (error) {
38
- throw new rest_1.HttpErrors.Unauthorized(`Error verifying token : ${error.message}`);
39
- }
40
- return userProfile;
41
- }
42
- async generateToken(userProfile) {
43
- if (!userProfile) {
44
- throw new rest_1.HttpErrors.Unauthorized('Error generating token : userProfile is null');
45
- }
46
- const userInfoForToken = {
47
- id: userProfile[security_1.securityId],
48
- name: userProfile.name,
49
- email: userProfile.email,
50
- };
51
- // Generate a JSON Web Token
52
- let token;
53
- try {
54
- token = await signAsync(userInfoForToken, this.jwtSecret, {
55
- expiresIn: Number(this.jwtExpiresIn),
56
- });
57
- }
58
- catch (error) {
59
- throw new rest_1.HttpErrors.Unauthorized(`Error encoding token : ${error}`);
60
- }
61
- return token;
62
- }
63
- };
64
- exports.JWTService = JWTService;
65
- exports.JWTService = JWTService = tslib_1.__decorate([
66
- tslib_1.__param(0, (0, core_1.inject)(keys_1.TokenServiceBindings.TOKEN_SECRET)),
67
- tslib_1.__param(1, (0, core_1.inject)(keys_1.TokenServiceBindings.TOKEN_EXPIRES_IN)),
68
- tslib_1.__metadata("design:paramtypes", [String, String])
69
- ], JWTService);
70
- //# sourceMappingURL=jwt.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":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AAC;SACH;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,WAAwB;QAC1C,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,iBAAU,CAAC,YAAY,CAC/B,8CAA8C,CAC/C,CAAC;SACH;QACD,MAAM,gBAAgB,GAAG;YACvB,EAAE,EAAE,WAAW,CAAC,qBAAU,CAAC;YAC3B,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,KAAK,EAAE,WAAW,CAAC,KAAK;SACzB,CAAC;QACF,4BAA4B;QAC5B,IAAI,KAAa,CAAC;QAClB,IAAI;YACF,KAAK,GAAG,MAAM,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,EAAE;gBACxD,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC;aACrC,CAAC,CAAC;SACJ;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,iBAAU,CAAC,YAAY,CAAC,0BAA0B,KAAK,EAAE,CAAC,CAAC;SACtE;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AA5DY,gCAAU;qBAAV,UAAU;IAElB,mBAAA,IAAA,aAAM,EAAC,2BAAoB,CAAC,YAAY,CAAC,CAAA;IAEzC,mBAAA,IAAA,aAAM,EAAC,2BAAoB,CAAC,gBAAgB,CAAC,CAAA;;GAJrC,UAAU,CA4DtB"}
@@ -1,8 +0,0 @@
1
- import { ReferenceObject, SecuritySchemeObject } from '@loopback/rest';
2
- export declare const OPERATION_SECURITY_SPEC: {
3
- jwt: never[];
4
- }[];
5
- export type SecuritySchemeObjects = {
6
- [securityScheme: string]: SecuritySchemeObject | ReferenceObject;
7
- };
8
- export declare const SECURITY_SCHEME_SPEC: SecuritySchemeObjects;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SECURITY_SCHEME_SPEC = exports.OPERATION_SECURITY_SPEC = void 0;
8
- exports.OPERATION_SECURITY_SPEC = [{ jwt: [] }];
9
- exports.SECURITY_SCHEME_SPEC = {
10
- jwt: {
11
- type: 'http',
12
- scheme: 'bearer',
13
- bearerFormat: 'JWT',
14
- },
15
- };
16
- //# sourceMappingURL=security.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security.spec.js","sourceRoot":"","sources":["../../../../src/components/jwt-authentication/services/security.spec.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;AAInD,QAAA,uBAAuB,GAAG,CAAC,EAAC,GAAG,EAAE,EAAE,EAAC,CAAC,CAAC;AAItC,QAAA,oBAAoB,GAA0B;IACzD,GAAG,EAAE;QACH,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,QAAQ;QAChB,YAAY,EAAE,KAAK;KACpB;CACF,CAAC"}
@@ -1,18 +0,0 @@
1
- import { UserService } from '@loopback/authentication';
2
- import { UserProfile } from '@loopback/security';
3
- import { User } from '../../../models/user.model';
4
- import { UserRepository } from '../../../repositories/user.repository';
5
- /**
6
- * A pre-defined type for user credentials. It assumes a user logs in
7
- * using the email and password. You can modify it if your app has different credential fields
8
- */
9
- export type Credentials = {
10
- email: string;
11
- password: string;
12
- };
13
- export declare class MyUserService implements UserService<User, Credentials> {
14
- userRepository: UserRepository;
15
- constructor(userRepository: UserRepository);
16
- verifyCredentials(credentials: Credentials): Promise<User>;
17
- convertToUserProfile(user: User): UserProfile;
18
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
3
- // Node module: @loopback/example-access-control-migration
4
- // This file is licensed under the MIT License.
5
- // License text available at https://opensource.org/licenses/MIT
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.MyUserService = void 0;
8
- const tslib_1 = require("tslib");
9
- const repository_1 = require("@loopback/repository");
10
- const rest_1 = require("@loopback/rest");
11
- const security_1 = require("@loopback/security");
12
- const bcryptjs_1 = require("bcryptjs");
13
- const user_repository_1 = require("../../../repositories/user.repository");
14
- let MyUserService = class MyUserService {
15
- constructor(userRepository) {
16
- this.userRepository = userRepository;
17
- }
18
- async verifyCredentials(credentials) {
19
- const invalidCredentialsError = 'Invalid email or password.';
20
- const foundUser = await this.userRepository.findOne({
21
- where: { email: credentials.email },
22
- });
23
- if (!foundUser) {
24
- throw new rest_1.HttpErrors.Unauthorized(invalidCredentialsError);
25
- }
26
- const credentialsFound = await this.userRepository.findCredentials(foundUser.id);
27
- if (!credentialsFound) {
28
- throw new rest_1.HttpErrors.Unauthorized(invalidCredentialsError);
29
- }
30
- const passwordMatched = await (0, bcryptjs_1.compare)(credentials.password, credentialsFound.password);
31
- if (!passwordMatched) {
32
- throw new rest_1.HttpErrors.Unauthorized(invalidCredentialsError);
33
- }
34
- return foundUser;
35
- }
36
- convertToUserProfile(user) {
37
- return {
38
- [security_1.securityId]: user.id.toString(),
39
- name: user.username,
40
- id: user.id,
41
- email: user.email,
42
- };
43
- }
44
- };
45
- exports.MyUserService = MyUserService;
46
- exports.MyUserService = MyUserService = tslib_1.__decorate([
47
- tslib_1.__param(0, (0, repository_1.repository)(user_repository_1.UserRepository)),
48
- tslib_1.__metadata("design:paramtypes", [user_repository_1.UserRepository])
49
- ], MyUserService);
50
- //# sourceMappingURL=user.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.service.js","sourceRoot":"","sources":["../../../../src/components/jwt-authentication/services/user.service.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAA+C;AAC/C,gEAAgE;;;;AAGhE,qDAAgD;AAChD,yCAA0C;AAC1C,iDAA2D;AAC3D,uCAAiC;AAEjC,2EAAqE;AAWrE,IAAa,aAAa,GAA1B,MAAa,aAAa;I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BM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- export * from './jwt-authentication-component';
7
- export * from './keys';
8
- export * from './services';
@@ -1,37 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- import {registerAuthenticationStrategy} from '@loopback/authentication';
7
- import {
8
- Application,
9
- Binding,
10
- Component,
11
- CoreBindings,
12
- inject,
13
- } from '@loopback/core';
14
- import {
15
- TokenServiceBindings,
16
- TokenServiceConstants,
17
- UserServiceBindings,
18
- } from './keys';
19
- import {JWTAuthenticationStrategy} from './services/jwt.auth.strategy';
20
- import {JWTService} from './services/jwt.service';
21
- import {MyUserService} from './services/user.service';
22
-
23
- export class JWTAuthenticationComponent implements Component {
24
- bindings: Binding[] = [
25
- Binding.bind(TokenServiceBindings.TOKEN_SECRET).to(
26
- TokenServiceConstants.TOKEN_SECRET_VALUE,
27
- ),
28
- Binding.bind(TokenServiceBindings.TOKEN_EXPIRES_IN).to(
29
- TokenServiceConstants.TOKEN_EXPIRES_IN_VALUE,
30
- ),
31
- Binding.bind(TokenServiceBindings.TOKEN_SERVICE).toClass(JWTService),
32
- Binding.bind(UserServiceBindings.USER_SERVICE).toClass(MyUserService),
33
- ];
34
- constructor(@inject(CoreBindings.APPLICATION_INSTANCE) app: Application) {
35
- registerAuthenticationStrategy(app, JWTAuthenticationStrategy);
36
- }
37
- }
@@ -1,34 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- import {TokenService, UserService} from '@loopback/authentication';
7
- import {BindingKey} from '@loopback/core';
8
- // The User model is imported from the application,
9
- // which makes the component not entirely independent
10
- import {User} from '../../models/user.model';
11
- import {Credentials} from './services/user.service';
12
-
13
- export namespace TokenServiceConstants {
14
- export const TOKEN_SECRET_VALUE = 'myjwts3cr3t';
15
- export const TOKEN_EXPIRES_IN_VALUE = '21600';
16
- }
17
-
18
- export namespace TokenServiceBindings {
19
- export const TOKEN_SECRET = BindingKey.create<string>(
20
- 'authentication.jwt.secret',
21
- );
22
- export const TOKEN_EXPIRES_IN = BindingKey.create<string>(
23
- 'authentication.jwt.expires.in.seconds',
24
- );
25
- export const TOKEN_SERVICE = BindingKey.create<TokenService>(
26
- 'services.authentication.jwt.tokenservice',
27
- );
28
- }
29
-
30
- export namespace UserServiceBindings {
31
- export const USER_SERVICE = BindingKey.create<UserService<User, Credentials>>(
32
- 'services.user.service',
33
- );
34
- }
@@ -1,9 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- export * from './jwt.auth.strategy';
7
- export * from './jwt.service';
8
- export * from './security.spec';
9
- export * from './user.service';
@@ -1,50 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- import {AuthenticationStrategy, TokenService} from '@loopback/authentication';
7
- import {inject} from '@loopback/core';
8
- import {HttpErrors, Request} from '@loopback/rest';
9
- import {UserProfile} from '@loopback/security';
10
- import {TokenServiceBindings} from '../keys';
11
-
12
- export class JWTAuthenticationStrategy implements AuthenticationStrategy {
13
- name = 'jwt';
14
-
15
- constructor(
16
- @inject(TokenServiceBindings.TOKEN_SERVICE)
17
- public tokenService: TokenService,
18
- ) {}
19
-
20
- async authenticate(request: Request): Promise<UserProfile | undefined> {
21
- const token: string = this.extractCredentials(request);
22
- const userProfile: UserProfile = await this.tokenService.verifyToken(token);
23
- return userProfile;
24
- }
25
-
26
- extractCredentials(request: Request): string {
27
- if (!request.headers.authorization) {
28
- throw new HttpErrors.Unauthorized(`Authorization header not found.`);
29
- }
30
-
31
- // for example : Bearer xxx.yyy.zzz
32
- const authHeaderValue = request.headers.authorization;
33
-
34
- if (!authHeaderValue.startsWith('Bearer')) {
35
- throw new HttpErrors.Unauthorized(
36
- `Authorization header is not of type 'Bearer'.`,
37
- );
38
- }
39
-
40
- //split the string into 2 parts : 'Bearer ' and the `xxx.yyy.zzz`
41
- const parts = authHeaderValue.split(' ');
42
- if (parts.length !== 2)
43
- throw new HttpErrors.Unauthorized(
44
- `Authorization header value has too many parts. It must follow the pattern: 'Bearer xx.yy.zz' where xx.yy.zz is a valid JWT token.`,
45
- );
46
- const token = parts[1];
47
-
48
- return token;
49
- }
50
- }
@@ -1,77 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- import {TokenService} from '@loopback/authentication';
7
- import {inject} from '@loopback/core';
8
- import {HttpErrors} from '@loopback/rest';
9
- import {securityId, UserProfile} from '@loopback/security';
10
- import {promisify} from 'util';
11
- import {TokenServiceBindings} from '../keys';
12
-
13
- const jwt = require('jsonwebtoken');
14
- const signAsync = promisify(jwt.sign);
15
- const verifyAsync = promisify(jwt.verify);
16
-
17
- export class JWTService implements TokenService {
18
- constructor(
19
- @inject(TokenServiceBindings.TOKEN_SECRET)
20
- private jwtSecret: string,
21
- @inject(TokenServiceBindings.TOKEN_EXPIRES_IN)
22
- private jwtExpiresIn: string,
23
- ) {}
24
-
25
- async verifyToken(token: string): Promise<UserProfile> {
26
- if (!token) {
27
- throw new HttpErrors.Unauthorized(
28
- `Error verifying token : 'token' is null`,
29
- );
30
- }
31
-
32
- let userProfile: UserProfile;
33
-
34
- try {
35
- // decode user profile from token
36
- const decodedToken = await verifyAsync(token, this.jwtSecret);
37
- // don't copy over token field 'iat' and 'exp', nor 'email' to user profile
38
- userProfile = Object.assign(
39
- {[securityId]: '', name: ''},
40
- {
41
- [securityId]: decodedToken.id,
42
- name: decodedToken.name,
43
- id: decodedToken.id,
44
- },
45
- );
46
- } catch (error) {
47
- throw new HttpErrors.Unauthorized(
48
- `Error verifying token : ${error.message}`,
49
- );
50
- }
51
- return userProfile;
52
- }
53
-
54
- async generateToken(userProfile: UserProfile): Promise<string> {
55
- if (!userProfile) {
56
- throw new HttpErrors.Unauthorized(
57
- 'Error generating token : userProfile is null',
58
- );
59
- }
60
- const userInfoForToken = {
61
- id: userProfile[securityId],
62
- name: userProfile.name,
63
- email: userProfile.email,
64
- };
65
- // Generate a JSON Web Token
66
- let token: string;
67
- try {
68
- token = await signAsync(userInfoForToken, this.jwtSecret, {
69
- expiresIn: Number(this.jwtExpiresIn),
70
- });
71
- } catch (error) {
72
- throw new HttpErrors.Unauthorized(`Error encoding token : ${error}`);
73
- }
74
-
75
- return token;
76
- }
77
- }
@@ -1,18 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- import {ReferenceObject, SecuritySchemeObject} from '@loopback/rest';
7
-
8
- export const OPERATION_SECURITY_SPEC = [{jwt: []}];
9
- export type SecuritySchemeObjects = {
10
- [securityScheme: string]: SecuritySchemeObject | ReferenceObject;
11
- };
12
- export const SECURITY_SCHEME_SPEC: SecuritySchemeObjects = {
13
- jwt: {
14
- type: 'http',
15
- scheme: 'bearer',
16
- bearerFormat: 'JWT',
17
- },
18
- };
@@ -1,65 +0,0 @@
1
- // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
- // Node module: @loopback/example-access-control-migration
3
- // This file is licensed under the MIT License.
4
- // License text available at https://opensource.org/licenses/MIT
5
-
6
- import {UserService} from '@loopback/authentication';
7
- import {repository} from '@loopback/repository';
8
- import {HttpErrors} from '@loopback/rest';
9
- import {securityId, UserProfile} from '@loopback/security';
10
- import {compare} from 'bcryptjs';
11
- import {User} from '../../../models/user.model';
12
- import {UserRepository} from '../../../repositories/user.repository';
13
-
14
- /**
15
- * A pre-defined type for user credentials. It assumes a user logs in
16
- * using the email and password. You can modify it if your app has different credential fields
17
- */
18
- export type Credentials = {
19
- email: string;
20
- password: string;
21
- };
22
-
23
- export class MyUserService implements UserService<User, Credentials> {
24
- constructor(
25
- @repository(UserRepository) public userRepository: UserRepository,
26
- ) {}
27
-
28
- async verifyCredentials(credentials: Credentials): Promise<User> {
29
- const invalidCredentialsError = 'Invalid email or password.';
30
-
31
- const foundUser = await this.userRepository.findOne({
32
- where: {email: credentials.email},
33
- });
34
- if (!foundUser) {
35
- throw new HttpErrors.Unauthorized(invalidCredentialsError);
36
- }
37
-
38
- const credentialsFound = await this.userRepository.findCredentials(
39
- foundUser.id,
40
- );
41
- if (!credentialsFound) {
42
- throw new HttpErrors.Unauthorized(invalidCredentialsError);
43
- }
44
-
45
- const passwordMatched = await compare(
46
- credentials.password,
47
- credentialsFound.password,
48
- );
49
-
50
- if (!passwordMatched) {
51
- throw new HttpErrors.Unauthorized(invalidCredentialsError);
52
- }
53
-
54
- return foundUser;
55
- }
56
-
57
- convertToUserProfile(user: User): UserProfile {
58
- return {
59
- [securityId]: user.id.toString(),
60
- name: user.username,
61
- id: user.id,
62
- email: user.email,
63
- };
64
- }
65
- }