@feathersjs/authentication-local 5.0.0-pre.21 → 5.0.0-pre.24

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 CHANGED
@@ -3,6 +3,33 @@
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
+ # [5.0.0-pre.24](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.23...v5.0.0-pre.24) (2022-06-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * **authentication-local:** Add passwordHash property resolver ([#2660](https://github.com/feathersjs/feathers/issues/2660)) ([b41279b](https://github.com/feathersjs/feathers/commit/b41279b55eea3771a6fa4983a37be2413287bbc6))
12
+
13
+
14
+
15
+
16
+
17
+ # [5.0.0-pre.23](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.22...v5.0.0-pre.23) (2022-06-06)
18
+
19
+ **Note:** Version bump only for package @feathersjs/authentication-local
20
+
21
+
22
+
23
+
24
+
25
+ # [5.0.0-pre.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24)
26
+
27
+ **Note:** Version bump only for package @feathersjs/authentication-local
28
+
29
+
30
+
31
+
32
+
6
33
  # [5.0.0-pre.21](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.20...v5.0.0-pre.21) (2022-05-23)
7
34
 
8
35
  **Note:** Version bump only for package @feathersjs/authentication-local
@@ -3,4 +3,10 @@ export interface HashPasswordOptions {
3
3
  authentication?: string;
4
4
  strategy?: string;
5
5
  }
6
+ /**
7
+ * @deprecated Use Feathers schema resolvers and the `passwordHash` resolver instead
8
+ * @param field
9
+ * @param options
10
+ * @returns
11
+ */
6
12
  export default function hashPassword(field: string, options?: HashPasswordOptions): (context: HookContext, next?: NextFunction) => Promise<any>;
@@ -9,6 +9,12 @@ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
9
9
  const errors_1 = require("@feathersjs/errors");
10
10
  const commons_1 = require("@feathersjs/commons");
11
11
  const debug = (0, commons_1.createDebug)('@feathersjs/authentication-local/hooks/hash-password');
12
+ /**
13
+ * @deprecated Use Feathers schema resolvers and the `passwordHash` resolver instead
14
+ * @param field
15
+ * @param options
16
+ * @returns
17
+ */
12
18
  function hashPassword(field, options = {}) {
13
19
  if (!field) {
14
20
  throw new Error('The hashPassword hook requires a field name option');
@@ -34,8 +40,9 @@ function hashPassword(field, options = {}) {
34
40
  const hashedPassword = await localStrategy.hashPassword(password, params);
35
41
  return (0, set_1.default)((0, cloneDeep_1.default)(data), field, hashedPassword);
36
42
  };
37
- context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) :
38
- await addHashedPassword(data);
43
+ context.data = Array.isArray(data)
44
+ ? await Promise.all(data.map(addHashedPassword))
45
+ : await addHashedPassword(data);
39
46
  }
40
47
  if (typeof next === 'function') {
41
48
  return next();
@@ -1 +1 @@
1
- {"version":3,"file":"hash-password.js","sourceRoot":"","sources":["../../src/hooks/hash-password.ts"],"names":[],"mappings":";;;;;AAAA,qDAA6B;AAC7B,qDAA6B;AAC7B,iEAAyC;AACzC,+CAAgD;AAChD,iDAAkD;AAIlD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,sDAAsD,CAAC,CAAC;AAOlF,SAAwB,YAAY,CAAE,KAAa,EAAE,UAA+B,EAAE;IACpF,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;IAED,OAAO,KAAK,EAAE,OAAoB,EAAE,IAAmB,EAAE,EAAE;QACzD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEtC,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,MAAM,WAAW,GAAG,GAAG,CAAC,qBAAqB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;YACtE,MAAM,EAAE,QAAQ,GAAG,OA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AO,IAAI,CAAA;iBACZ;gBAED,MAAM,cAAc,GAAW,MAAM,aAAa,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;gBAEjF,OAAO,IAAA,aAAG,EAAC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAA;YACpD,CAAC,CAAA;YAED,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;gBAChC,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;gBAChD,CAAC,CAAC,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAA;SAClC;QAED,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,OAAO,IAAI,EAAE,CAAA;SACd;IACH,CAAC,CAAA;AACH,CAAC;AA5CD,+BA4CC"}
@@ -1,3 +1,7 @@
1
1
  import { HookContext, NextFunction } from '@feathersjs/feathers';
2
+ /**
3
+ * @deprecated For reliable safe data representations use Feathers schema dispatch resolvers.
4
+ * See https://dove.docs.feathersjs.com/api/schema/resolvers.html#safe-data-resolvers for more information.
5
+ */
2
6
  declare const _default: (...fields: string[]) => (context: HookContext, next?: NextFunction) => Promise<void>;
3
7
  export default _default;
@@ -4,11 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const omit_1 = __importDefault(require("lodash/omit"));
7
+ /**
8
+ * @deprecated For reliable safe data representations use Feathers schema dispatch resolvers.
9
+ * See https://dove.docs.feathersjs.com/api/schema/resolvers.html#safe-data-resolvers for more information.
10
+ */
7
11
  exports.default = (...fields) => {
8
12
  const o = (current) => {
9
13
  if (typeof current === 'object' && !Array.isArray(current)) {
10
- const data = typeof current.toJSON === 'function'
11
- ? current.toJSON() : current;
14
+ const data = typeof current.toJSON === 'function' ? current.toJSON() : current;
12
15
  return (0, omit_1.default)(data, fields);
13
16
  }
14
17
  return current;
@@ -1 +1 @@
1
- {"version":3,"file":"protect.js","sourceRoot":"","sources":["../../src/hooks/protect.ts"],"names":[],"mappings":";;;;;AAAA,uDAA+B;AAG/B,kBAAe,CAAC,GAAG,MAAgB,EAAE,EAAE;IACrC,MAAM,CAAC,GAAG,CAAC,OAAY,EAAE,EAAE;QACzB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC1D,MAAM,IAAI,GAAG,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU;gBAC/C,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAE/B,OAAO,IAAA,cAAI,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;SAC3B;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO,KAAK,EAAE,OAAoB,EAAE,IAAmB,EAAE,EAAE;QACzD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,MAAM,IAAI,EAAE,CAAC;SACd;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;QAElD,IAAI,MAAM,EAAE;YACV,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACzB,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aAClC;iBAAM,IAAI,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;gBACnD,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE;oBAC3C,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;iBACzB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,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E,EAAE,MAAM,EAAE;oBAC3C,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;iBACzB,CAAC,CAAA;aACH;iBAAM;gBACL,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;aAC7B;YAED,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAC7C,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAA;aAClC;SACF;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,19 @@
1
+ import { HookContext } from '@feathersjs/feathers';
1
2
  import hashPassword from './hooks/hash-password';
3
+ import { LocalStrategy } from './strategy';
2
4
  export declare const hooks: {
3
5
  hashPassword: typeof hashPassword;
4
- protect: (...fields: string[]) => (context: import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>, next?: import("@feathersjs/hooks").NextFunction) => Promise<void>;
6
+ protect: (...fields: string[]) => (context: HookContext<import("@feathersjs/feathers").Application<any, any>, any>, next?: import("@feathersjs/feathers").NextFunction) => Promise<void>;
5
7
  };
6
- export { LocalStrategy } from './strategy';
8
+ export { LocalStrategy };
9
+ /**
10
+ * Returns as property resolver that hashes a given plain text password using a Local
11
+ * authentication strategy.
12
+ *
13
+ * @param options The authentication `service` and `strategy` name
14
+ * @returns
15
+ */
16
+ export declare const passwordHash: (options: {
17
+ service?: string;
18
+ strategy: string;
19
+ }) => <H extends HookContext<any, any>>(value: string | undefined, _data: any, context: H) => Promise<string>;
package/lib/index.js CHANGED
@@ -3,10 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LocalStrategy = exports.hooks = void 0;
6
+ exports.passwordHash = exports.LocalStrategy = exports.hooks = void 0;
7
7
  const hash_password_1 = __importDefault(require("./hooks/hash-password"));
8
8
  const protect_1 = __importDefault(require("./hooks/protect"));
9
- exports.hooks = { hashPassword: hash_password_1.default, protect: protect_1.default };
10
- var strategy_1 = require("./strategy");
9
+ const strategy_1 = require("./strategy");
11
10
  Object.defineProperty(exports, "LocalStrategy", { enumerable: true, get: function () { return strategy_1.LocalStrategy; } });
11
+ exports.hooks = { hashPassword: hash_password_1.default, protect: protect_1.default };
12
+ /**
13
+ * Returns as property resolver that hashes a given plain text password using a Local
14
+ * authentication strategy.
15
+ *
16
+ * @param options The authentication `service` and `strategy` name
17
+ * @returns
18
+ */
19
+ const passwordHash = (options) => async (value, _data, context) => {
20
+ const { app, params } = context;
21
+ const authService = app.defaultAuthentication(options.service);
22
+ const localStrategy = authService.getStrategy(options.strategy);
23
+ return localStrategy.hashPassword(value, params);
24
+ };
25
+ exports.passwordHash = passwordHash;
12
26
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAiD;AACjD,8DAAsC;AAEzB,QAAA,KAAK,GAAG,EAAE,YAAY,EAAZ,uBAAY,EAAE,OAAO,EAAP,iBAAO,EAAE,CAAC;AAC/C,uCAA2C;AAAlC,yGAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,0EAAgD;AAChD,8DAAqC;AACrC,yCAA0C;AAGjC,8FAHA,wBAAa,OAGA;AADT,QAAA,KAAK,GAAG,EAAE,YAAY,EAAZ,uBAAY,EAAE,OAAO,EAAP,iBAAO,EAAE,CAAA;AAG9C;;;;;;GAMG;AACI,MAAM,YAAY,GACvB,CAAC,OAA+C,EAAE,EAAE,CACpD,KAAK,EAAmC,KAAyB,EAAE,KAAU,EAAE,OAAU,EAAE,EAAE;IAC3F,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC/B,MAAM,WAAW,GAAG,GAAG,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9D,MAAM,aAAa,GAAG,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAkB,CAAA;IAEhF,OAAO,aAAa,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC,CAAA;AARU,QAAA,YAAY,gBAQtB"}
package/lib/strategy.js CHANGED
@@ -15,7 +15,7 @@ const debug = (0, commons_1.createDebug)('@feathersjs/authentication-local/strat
15
15
  class LocalStrategy extends authentication_1.AuthenticationBaseStrategy {
16
16
  verifyConfiguration() {
17
17
  const config = this.configuration;
18
- ['usernameField', 'passwordField'].forEach(prop => {
18
+ ['usernameField', 'passwordField'].forEach((prop) => {
19
19
  if (typeof config[prop] !== 'string') {
20
20
  throw new Error(`'${this.name}' authentication strategy requires a '${prop}' setting`);
21
21
  }
@@ -43,7 +43,8 @@ class LocalStrategy extends authentication_1.AuthenticationBaseStrategy {
43
43
  }
44
44
  async findEntity(username, params) {
45
45
  const { entityUsernameField, errorMessage } = this.configuration;
46
- if (!username) { // don't query for users without any condition set.
46
+ if (!username) {
47
+ // don't query for users without any condition set.
47
48
  throw new errors_1.NotAuthenticated(errorMessage);
48
49
  }
49
50
  const query = await this.getEntityQuery({
@@ -97,7 +98,8 @@ class LocalStrategy extends authentication_1.AuthenticationBaseStrategy {
97
98
  const { passwordField, usernameField, entity, errorMessage } = this.configuration;
98
99
  const username = data[usernameField];
99
100
  const password = data[passwordField];
100
- if (!password) { // exit early if there is no password
101
+ if (!password) {
102
+ // exit early if there is no password
101
103
  throw new errors_1.NotAuthenticated(errorMessage);
102
104
  }
103
105
  const result = await this.findEntity(username, (0, omit_1.default)(params, 'provider'));
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;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AAC,CAAA;QAEnD,IAAI,MAAM,EAAE;YACV,OAAO,MAAM,CAAA;SACd;QAED,MAAM,IAAI,yBAAgB,CAAC,YAAY,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,OAAe;QAClD,OAAO,kBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAA2B,EAAE,MAAc;QAC5D,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,aAAa,CAAA;QACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAA;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAA;QAEpC,IAAI,CAAC,QAAQ,EAAE;YACb,qCAAqC;YACrC,MAAM,IAAI,yBAAgB,CAAC,YAAY,CAAC,CAAA;SACzC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAA,cAAI,EAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;QAExE,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAE5C,OAAO;YACL,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE;YACvC,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;SAC/C,CAAA;IACH,CAAC;CACF;AAlID,sCAkIC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@feathersjs/authentication-local",
3
3
  "description": "Local authentication strategy for @feathers/authentication",
4
- "version": "5.0.0-pre.21",
4
+ "version": "5.0.0-pre.24",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -52,23 +52,24 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@feathersjs/authentication": "^5.0.0-pre.21",
56
- "@feathersjs/commons": "^5.0.0-pre.20",
57
- "@feathersjs/errors": "^5.0.0-pre.21",
58
- "@feathersjs/feathers": "^5.0.0-pre.21",
55
+ "@feathersjs/authentication": "^5.0.0-pre.24",
56
+ "@feathersjs/commons": "^5.0.0-pre.24",
57
+ "@feathersjs/errors": "^5.0.0-pre.24",
58
+ "@feathersjs/feathers": "^5.0.0-pre.24",
59
59
  "bcryptjs": "^2.4.3",
60
60
  "lodash": "^4.17.21"
61
61
  },
62
62
  "devDependencies": {
63
- "@feathersjs/memory": "^5.0.0-pre.21",
63
+ "@feathersjs/memory": "^5.0.0-pre.24",
64
+ "@feathersjs/schema": "^5.0.0-pre.24",
64
65
  "@types/bcryptjs": "^2.4.2",
65
66
  "@types/lodash": "^4.14.182",
66
67
  "@types/mocha": "^9.1.1",
67
- "@types/node": "^17.0.31",
68
+ "@types/node": "^17.0.40",
68
69
  "mocha": "^10.0.0",
69
70
  "shx": "^0.3.4",
70
- "ts-node": "^10.7.0",
71
- "typescript": "^4.6.4"
71
+ "ts-node": "^10.8.1",
72
+ "typescript": "^4.7.3"
72
73
  },
73
- "gitHead": "ac3baed231f72370a80a06c5944538915479b96e"
74
+ "gitHead": "72779fa2938f43d7b345b6861ff0035481a07de3"
74
75
  }
@@ -1,59 +1,66 @@
1
- import get from 'lodash/get';
2
- import set from 'lodash/set';
3
- import cloneDeep from 'lodash/cloneDeep';
4
- import { BadRequest } from '@feathersjs/errors';
5
- import { createDebug } from '@feathersjs/commons';
6
- import { HookContext, NextFunction } from '@feathersjs/feathers';
7
- import { LocalStrategy } from '../strategy';
1
+ import get from 'lodash/get'
2
+ import set from 'lodash/set'
3
+ import cloneDeep from 'lodash/cloneDeep'
4
+ import { BadRequest } from '@feathersjs/errors'
5
+ import { createDebug } from '@feathersjs/commons'
6
+ import { HookContext, NextFunction } from '@feathersjs/feathers'
7
+ import { LocalStrategy } from '../strategy'
8
8
 
9
- const debug = createDebug('@feathersjs/authentication-local/hooks/hash-password');
9
+ const debug = createDebug('@feathersjs/authentication-local/hooks/hash-password')
10
10
 
11
11
  export interface HashPasswordOptions {
12
- authentication?: string;
13
- strategy?: string;
12
+ authentication?: string
13
+ strategy?: string
14
14
  }
15
15
 
16
- export default function hashPassword (field: string, options: HashPasswordOptions = {}) {
16
+ /**
17
+ * @deprecated Use Feathers schema resolvers and the `passwordHash` resolver instead
18
+ * @param field
19
+ * @param options
20
+ * @returns
21
+ */
22
+ export default function hashPassword(field: string, options: HashPasswordOptions = {}) {
17
23
  if (!field) {
18
- throw new Error('The hashPassword hook requires a field name option');
24
+ throw new Error('The hashPassword hook requires a field name option')
19
25
  }
20
26
 
21
27
  return async (context: HookContext, next?: NextFunction) => {
22
- const { app, data, params } = context;
28
+ const { app, data, params } = context
23
29
 
24
30
  if (data !== undefined) {
25
- const authService = app.defaultAuthentication(options.authentication);
26
- const { strategy = 'local' } = options;
31
+ const authService = app.defaultAuthentication(options.authentication)
32
+ const { strategy = 'local' } = options
27
33
 
28
34
  if (!authService || typeof authService.getStrategies !== 'function') {
29
- throw new BadRequest('Could not find an authentication service to hash password');
35
+ throw new BadRequest('Could not find an authentication service to hash password')
30
36
  }
31
37
 
32
- const [ localStrategy ] = authService.getStrategies(strategy) as LocalStrategy[];
38
+ const [localStrategy] = authService.getStrategies(strategy) as LocalStrategy[]
33
39
 
34
40
  if (!localStrategy || typeof localStrategy.hashPassword !== 'function') {
35
- throw new BadRequest(`Could not find '${strategy}' strategy to hash password`);
41
+ throw new BadRequest(`Could not find '${strategy}' strategy to hash password`)
36
42
  }
37
43
 
38
44
  const addHashedPassword = async (data: any) => {
39
- const password = get(data, field);
45
+ const password = get(data, field)
40
46
 
41
47
  if (password === undefined) {
42
- debug(`hook.data.${field} is undefined, not hashing password`);
43
- return data;
48
+ debug(`hook.data.${field} is undefined, not hashing password`)
49
+ return data
44
50
  }
45
51
 
46
- const hashedPassword: string = await localStrategy.hashPassword(password, params);
52
+ const hashedPassword: string = await localStrategy.hashPassword(password, params)
47
53
 
48
- return set(cloneDeep(data), field, hashedPassword);
54
+ return set(cloneDeep(data), field, hashedPassword)
49
55
  }
50
56
 
51
- context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) :
52
- await addHashedPassword(data);
57
+ context.data = Array.isArray(data)
58
+ ? await Promise.all(data.map(addHashedPassword))
59
+ : await addHashedPassword(data)
53
60
  }
54
61
 
55
62
  if (typeof next === 'function') {
56
- return next();
63
+ return next()
57
64
  }
58
- };
65
+ }
59
66
  }
@@ -1,39 +1,42 @@
1
- import omit from 'lodash/omit';
2
- import { HookContext, NextFunction } from '@feathersjs/feathers';
1
+ import omit from 'lodash/omit'
2
+ import { HookContext, NextFunction } from '@feathersjs/feathers'
3
3
 
4
+ /**
5
+ * @deprecated For reliable safe data representations use Feathers schema dispatch resolvers.
6
+ * See https://dove.docs.feathersjs.com/api/schema/resolvers.html#safe-data-resolvers for more information.
7
+ */
4
8
  export default (...fields: string[]) => {
5
9
  const o = (current: any) => {
6
10
  if (typeof current === 'object' && !Array.isArray(current)) {
7
- const data = typeof current.toJSON === 'function'
8
- ? current.toJSON() : current;
11
+ const data = typeof current.toJSON === 'function' ? current.toJSON() : current
9
12
 
10
- return omit(data, fields);
13
+ return omit(data, fields)
11
14
  }
12
15
 
13
- return current;
14
- };
16
+ return current
17
+ }
15
18
 
16
19
  return async (context: HookContext, next?: NextFunction) => {
17
20
  if (typeof next === 'function') {
18
- await next();
21
+ await next()
19
22
  }
20
23
 
21
- const result = context.dispatch || context.result;
24
+ const result = context.dispatch || context.result
22
25
 
23
26
  if (result) {
24
27
  if (Array.isArray(result)) {
25
- context.dispatch = result.map(o);
28
+ context.dispatch = result.map(o)
26
29
  } else if (result.data && context.method === 'find') {
27
30
  context.dispatch = Object.assign({}, result, {
28
31
  data: result.data.map(o)
29
- });
32
+ })
30
33
  } else {
31
- context.dispatch = o(result);
34
+ context.dispatch = o(result)
32
35
  }
33
36
 
34
37
  if (context.params && context.params.provider) {
35
- context.result = context.dispatch;
38
+ context.result = context.dispatch
36
39
  }
37
40
  }
38
- };
39
- };
41
+ }
42
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,24 @@
1
- import hashPassword from './hooks/hash-password';
2
- import protect from './hooks/protect';
1
+ import { HookContext } from '@feathersjs/feathers'
2
+ import hashPassword from './hooks/hash-password'
3
+ import protect from './hooks/protect'
4
+ import { LocalStrategy } from './strategy'
3
5
 
4
- export const hooks = { hashPassword, protect };
5
- export { LocalStrategy } from './strategy';
6
+ export const hooks = { hashPassword, protect }
7
+ export { LocalStrategy }
8
+
9
+ /**
10
+ * Returns as property resolver that hashes a given plain text password using a Local
11
+ * authentication strategy.
12
+ *
13
+ * @param options The authentication `service` and `strategy` name
14
+ * @returns
15
+ */
16
+ export const passwordHash =
17
+ (options: { service?: string; strategy: string }) =>
18
+ async <H extends HookContext<any, any>>(value: string | undefined, _data: any, context: H) => {
19
+ const { app, params } = context
20
+ const authService = app.defaultAuthentication(options.service)
21
+ const localStrategy = authService.getStrategy(options.strategy) as LocalStrategy
22
+
23
+ return localStrategy.hashPassword(value, params)
24
+ }
package/src/strategy.ts CHANGED
@@ -1,30 +1,28 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import bcrypt from 'bcryptjs';
3
- import get from 'lodash/get';
4
- import omit from 'lodash/omit';
5
- import { NotAuthenticated } from '@feathersjs/errors';
6
- import { Query, Params } from '@feathersjs/feathers';
7
- import {
8
- AuthenticationRequest, AuthenticationBaseStrategy
9
- } from '@feathersjs/authentication';
10
- import { createDebug } from '@feathersjs/commons';
11
-
12
- const debug = createDebug('@feathersjs/authentication-local/strategy');
2
+ import bcrypt from 'bcryptjs'
3
+ import get from 'lodash/get'
4
+ import omit from 'lodash/omit'
5
+ import { NotAuthenticated } from '@feathersjs/errors'
6
+ import { Query, Params } from '@feathersjs/feathers'
7
+ import { AuthenticationRequest, AuthenticationBaseStrategy } from '@feathersjs/authentication'
8
+ import { createDebug } from '@feathersjs/commons'
9
+
10
+ const debug = createDebug('@feathersjs/authentication-local/strategy')
13
11
 
14
12
  export class LocalStrategy extends AuthenticationBaseStrategy {
15
- verifyConfiguration () {
16
- const config = this.configuration;
13
+ verifyConfiguration() {
14
+ const config = this.configuration
17
15
 
18
- [ 'usernameField', 'passwordField' ].forEach(prop => {
16
+ ;['usernameField', 'passwordField'].forEach((prop) => {
19
17
  if (typeof config[prop] !== 'string') {
20
- throw new Error(`'${this.name}' authentication strategy requires a '${prop}' setting`);
18
+ throw new Error(`'${this.name}' authentication strategy requires a '${prop}' setting`)
21
19
  }
22
- });
20
+ })
23
21
  }
24
22
 
25
- get configuration () {
26
- const authConfig = this.authentication.configuration;
27
- const config = super.configuration || {};
23
+ get configuration() {
24
+ const authConfig = this.authentication.configuration
25
+ const config = super.configuration || {}
28
26
 
29
27
  return {
30
28
  hashSize: 10,
@@ -35,105 +33,110 @@ export class LocalStrategy extends AuthenticationBaseStrategy {
35
33
  entityPasswordField: config.passwordField,
36
34
  entityUsernameField: config.usernameField,
37
35
  ...config
38
- };
36
+ }
39
37
  }
40
38
 
41
- async getEntityQuery (query: Query, _params: Params) {
39
+ async getEntityQuery(query: Query, _params: Params) {
42
40
  return {
43
41
  $limit: 1,
44
42
  ...query
45
- };
43
+ }
46
44
  }
47
45
 
48
- async findEntity (username: string, params: Params) {
49
- const { entityUsernameField, errorMessage } = this.configuration;
50
- if (!username) { // don't query for users without any condition set.
51
- throw new NotAuthenticated(errorMessage);
46
+ async findEntity(username: string, params: Params) {
47
+ const { entityUsernameField, errorMessage } = this.configuration
48
+ if (!username) {
49
+ // don't query for users without any condition set.
50
+ throw new NotAuthenticated(errorMessage)
52
51
  }
53
52
 
54
- const query = await this.getEntityQuery({
55
- [entityUsernameField]: username
56
- }, params);
53
+ const query = await this.getEntityQuery(
54
+ {
55
+ [entityUsernameField]: username
56
+ },
57
+ params
58
+ )
57
59
 
58
- const findParams = Object.assign({}, params, { query });
59
- const entityService = this.entityService;
60
+ const findParams = Object.assign({}, params, { query })
61
+ const entityService = this.entityService
60
62
 
61
- debug('Finding entity with query', params.query);
63
+ debug('Finding entity with query', params.query)
62
64
 
63
- const result = await entityService.find(findParams);
64
- const list = Array.isArray(result) ? result : result.data;
65
+ const result = await entityService.find(findParams)
66
+ const list = Array.isArray(result) ? result : result.data
65
67
 
66
68
  if (!Array.isArray(list) || list.length === 0) {
67
- debug('No entity found');
69
+ debug('No entity found')
68
70
 
69
- throw new NotAuthenticated(errorMessage);
71
+ throw new NotAuthenticated(errorMessage)
70
72
  }
71
73
 
72
- const [ entity ] = list;
74
+ const [entity] = list
73
75
 
74
- return entity;
76
+ return entity
75
77
  }
76
78
 
77
- async getEntity (result: any, params: Params) {
78
- const entityService = this.entityService;
79
- const { entityId = (entityService as any).id, entity } = this.configuration;
79
+ async getEntity(result: any, params: Params) {
80
+ const entityService = this.entityService
81
+ const { entityId = (entityService as any).id, entity } = this.configuration
80
82
 
81
83
  if (!entityId || result[entityId] === undefined) {
82
- throw new NotAuthenticated('Could not get local entity');
84
+ throw new NotAuthenticated('Could not get local entity')
83
85
  }
84
86
 
85
87
  if (!params.provider) {
86
- return result;
88
+ return result
87
89
  }
88
90
 
89
91
  return entityService.get(result[entityId], {
90
92
  ...params,
91
93
  [entity]: result
92
- });
94
+ })
93
95
  }
94
96
 
95
- async comparePassword (entity: any, password: string) {
96
- const { entityPasswordField, errorMessage } = this.configuration;
97
+ async comparePassword(entity: any, password: string) {
98
+ const { entityPasswordField, errorMessage } = this.configuration
97
99
  // find password in entity, this allows for dot notation
98
- const hash = get(entity, entityPasswordField);
100
+ const hash = get(entity, entityPasswordField)
99
101
 
100
102
  if (!hash) {
101
- debug(`Record is missing the '${entityPasswordField}' password field`);
103
+ debug(`Record is missing the '${entityPasswordField}' password field`)
102
104
 
103
- throw new NotAuthenticated(errorMessage);
105
+ throw new NotAuthenticated(errorMessage)
104
106
  }
105
107
 
106
- debug('Verifying password');
108
+ debug('Verifying password')
107
109
 
108
- const result = await bcrypt.compare(password, hash);
110
+ const result = await bcrypt.compare(password, hash)
109
111
 
110
112
  if (result) {
111
- return entity;
113
+ return entity
112
114
  }
113
115
 
114
- throw new NotAuthenticated(errorMessage);
116
+ throw new NotAuthenticated(errorMessage)
115
117
  }
116
118
 
117
- async hashPassword (password: string, _params: Params) {
118
- return bcrypt.hash(password, this.configuration.hashSize);
119
+ async hashPassword(password: string, _params: Params) {
120
+ return bcrypt.hash(password, this.configuration.hashSize)
119
121
  }
120
122
 
121
- async authenticate (data: AuthenticationRequest, params: Params) {
122
- const { passwordField, usernameField, entity, errorMessage } = this.configuration;
123
- const username = data[usernameField];
124
- const password = data[passwordField];
123
+ async authenticate(data: AuthenticationRequest, params: Params) {
124
+ const { passwordField, usernameField, entity, errorMessage } = this.configuration
125
+ const username = data[usernameField]
126
+ const password = data[passwordField]
125
127
 
126
- if (!password) { // exit early if there is no password
127
- throw new NotAuthenticated(errorMessage);
128
+ if (!password) {
129
+ // exit early if there is no password
130
+ throw new NotAuthenticated(errorMessage)
128
131
  }
129
132
 
130
- const result = await this.findEntity(username, omit(params, 'provider'));
133
+ const result = await this.findEntity(username, omit(params, 'provider'))
131
134
 
132
- await this.comparePassword(result, password);
135
+ await this.comparePassword(result, password)
133
136
 
134
137
  return {
135
138
  authentication: { strategy: this.name },
136
139
  [entity]: await this.getEntity(result, params)
137
- };
140
+ }
138
141
  }
139
142
  }