@feathersjs/authentication-local 5.0.0-pre.2 → 5.0.0-pre.20

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,182 @@
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.20](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.19...v5.0.0-pre.20) (2022-05-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **dependencies:** Lock monorepo package version numbers ([#2623](https://github.com/feathersjs/feathers/issues/2623)) ([5640c10](https://github.com/feathersjs/feathers/commit/5640c1020cc139994e695d658c08bad3494db507))
12
+
13
+
14
+
15
+
16
+
17
+ # [5.0.0-pre.19](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.18...v5.0.0-pre.19) (2022-05-01)
18
+
19
+
20
+ ### Features
21
+
22
+ * **typescript:** Improve adapter typings ([#2605](https://github.com/feathersjs/feathers/issues/2605)) ([3b2ca0a](https://github.com/feathersjs/feathers/commit/3b2ca0a6a8e03e8390272c4d7e930b4bffdaacf5))
23
+
24
+
25
+
26
+
27
+
28
+ # [5.0.0-pre.18](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.17...v5.0.0-pre.18) (2022-04-11)
29
+
30
+ **Note:** Version bump only for package @feathersjs/authentication-local
31
+
32
+
33
+
34
+
35
+
36
+ # [5.0.0-pre.17](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.16...v5.0.0-pre.17) (2022-02-15)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * **hooks:** Allow all built-in hooks to be used the async and regular way ([#2559](https://github.com/feathersjs/feathers/issues/2559)) ([8f9f631](https://github.com/feathersjs/feathers/commit/8f9f631e0ce89de349207db72def84e7ab496a4a))
42
+
43
+
44
+
45
+
46
+
47
+ # [5.0.0-pre.16](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.15...v5.0.0-pre.16) (2022-01-12)
48
+
49
+ **Note:** Version bump only for package @feathersjs/authentication-local
50
+
51
+
52
+
53
+
54
+
55
+ # [5.0.0-pre.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
56
+
57
+
58
+ ### Bug Fixes
59
+
60
+ * **typescript:** Overall typing improvements ([#2478](https://github.com/feathersjs/feathers/issues/2478)) ([b8eb804](https://github.com/feathersjs/feathers/commit/b8eb804158556d9651a8607e3c3fda15e0bfd110))
61
+
62
+
63
+
64
+
65
+
66
+ # [5.0.0-pre.14](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.13...v5.0.0-pre.14) (2021-10-13)
67
+
68
+ **Note:** Version bump only for package @feathersjs/authentication-local
69
+
70
+
71
+
72
+
73
+
74
+ # [5.0.0-pre.13](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.12...v5.0.0-pre.13) (2021-10-13)
75
+
76
+ **Note:** Version bump only for package @feathersjs/authentication-local
77
+
78
+
79
+
80
+
81
+
82
+ # [5.0.0-pre.12](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.11...v5.0.0-pre.12) (2021-10-12)
83
+
84
+ **Note:** Version bump only for package @feathersjs/authentication-local
85
+
86
+
87
+
88
+
89
+
90
+ # [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06)
91
+
92
+ **Note:** Version bump only for package @feathersjs/authentication-local
93
+
94
+
95
+
96
+
97
+
98
+ # [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19)
99
+
100
+
101
+ ### Bug Fixes
102
+
103
+ * **authentication-local:** adds error handling for undefined/null password field ([#2444](https://github.com/feathersjs/feathers/issues/2444)) ([4323f98](https://github.com/feathersjs/feathers/commit/4323f9859a66a7fe3f7f15d81476bd81b735c226))
104
+
105
+
106
+
107
+
108
+
109
+ # [5.0.0-pre.9](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.8...v5.0.0-pre.9) (2021-08-09)
110
+
111
+ **Note:** Version bump only for package @feathersjs/authentication-local
112
+
113
+
114
+
115
+
116
+
117
+ # [5.0.0-pre.8](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.7...v5.0.0-pre.8) (2021-08-09)
118
+
119
+ **Note:** Version bump only for package @feathersjs/authentication-local
120
+
121
+
122
+
123
+
124
+
125
+ # [5.0.0-pre.7](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.6...v5.0.0-pre.7) (2021-08-09)
126
+
127
+ **Note:** Version bump only for package @feathersjs/authentication-local
128
+
129
+
130
+
131
+
132
+
133
+ # [5.0.0-pre.6](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.5...v5.0.0-pre.6) (2021-08-08)
134
+
135
+ **Note:** Version bump only for package @feathersjs/authentication-local
136
+
137
+
138
+
139
+
140
+
141
+ # [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23)
142
+
143
+
144
+ ### Bug Fixes
145
+
146
+ * **hooks:** Migrate built-in hooks and allow backwards compatibility ([#2358](https://github.com/feathersjs/feathers/issues/2358)) ([759c5a1](https://github.com/feathersjs/feathers/commit/759c5a19327a731af965c3604119393b3d09a406))
147
+ * **koa:** Use extended query parser for compatibility ([#2397](https://github.com/feathersjs/feathers/issues/2397)) ([b2944ba](https://github.com/feathersjs/feathers/commit/b2944bac3ec6d5ecc80dc518cd4e58093692db74))
148
+
149
+
150
+ ### Features
151
+
152
+ * **adapter-commons:** Add support for params.adapter option and move memory adapter to @feathersjs/memory ([#2367](https://github.com/feathersjs/feathers/issues/2367)) ([a43e7da](https://github.com/feathersjs/feathers/commit/a43e7da22b6b981a96d1321736ea9a0cb924fb4f))
153
+
154
+
155
+
156
+
157
+
158
+ # [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13)
159
+
160
+ **Note:** Version bump only for package @feathersjs/authentication-local
161
+
162
+
163
+
164
+
165
+
166
+ # [5.0.0-pre.3](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.2...v5.0.0-pre.3) (2021-04-21)
167
+
168
+
169
+ ### Bug Fixes
170
+
171
+ * **typescript:** Improve TypeScript backwards compatibility ([#2310](https://github.com/feathersjs/feathers/issues/2310)) ([f33be73](https://github.com/feathersjs/feathers/commit/f33be73fc46a533efb15df9aab0658e3240d3897))
172
+
173
+
174
+ ### Features
175
+
176
+ * **dependencies:** Remove direct debug dependency ([#2296](https://github.com/feathersjs/feathers/issues/2296)) ([501d416](https://github.com/feathersjs/feathers/commit/501d4164d30c6a126906dc640cdfdc82207ba34a))
177
+
178
+
179
+
180
+
181
+
6
182
  # [5.0.0-pre.2](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.1...v5.0.0-pre.2) (2021-04-06)
7
183
 
8
184
  **Note:** Version bump only for package @feathersjs/authentication-local
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Feathers
3
+ Copyright (c) 2022 Feathers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @feathersjs/authentication-local
2
2
 
3
3
  [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
4
- [![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/authentication-local)](https://david-dm.org/feathersjs/feathers?path=packages/authentication-local)
5
4
  [![Download Status](https://img.shields.io/npm/dm/@feathersjs/authentication-local.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/authentication-local)
5
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
6
6
 
7
7
  > Local username and password authentication strategy for Feathers authentication
8
8
 
@@ -18,6 +18,6 @@ Refer to the [Feathers local authentication API documentation](https://docs.feat
18
18
 
19
19
  ## License
20
20
 
21
- Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
21
+ Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
22
 
23
23
  Licensed under the [MIT license](LICENSE).
@@ -1,6 +1,6 @@
1
- import { HookContext } from '@feathersjs/feathers';
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
2
  export interface HashPasswordOptions {
3
3
  authentication?: string;
4
4
  strategy?: string;
5
5
  }
6
- export default function hashPassword(field: string, options?: HashPasswordOptions): (context: HookContext<any, any>) => Promise<HookContext<any, any>>;
6
+ export default function hashPassword(field: string, options?: HashPasswordOptions): (context: HookContext, next?: NextFunction) => Promise<any>;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,43 +7,40 @@ const get_1 = __importDefault(require("lodash/get"));
16
7
  const set_1 = __importDefault(require("lodash/set"));
17
8
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
18
9
  const errors_1 = require("@feathersjs/errors");
19
- const debug_1 = __importDefault(require("debug"));
20
- const debug = debug_1.default('@feathersjs/authentication-local/hooks/hash-password');
10
+ const commons_1 = require("@feathersjs/commons");
11
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication-local/hooks/hash-password');
21
12
  function hashPassword(field, options = {}) {
22
13
  if (!field) {
23
14
  throw new Error('The hashPassword hook requires a field name option');
24
15
  }
25
- return (context) => __awaiter(this, void 0, void 0, function* () {
26
- if (context.type !== 'before') {
27
- throw new Error('The \'hashPassword\' hook should only be used as a \'before\' hook');
28
- }
16
+ return async (context, next) => {
29
17
  const { app, data, params } = context;
30
- if (data === undefined) {
31
- debug('hook.data is undefined. Skipping hashPassword hook.');
32
- return context;
33
- }
34
- const authService = app.defaultAuthentication(options.authentication);
35
- const { strategy = 'local' } = options;
36
- if (!authService || typeof authService.getStrategies !== 'function') {
37
- throw new errors_1.BadRequest('Could not find an authentication service to hash password');
18
+ if (data !== undefined) {
19
+ const authService = app.defaultAuthentication(options.authentication);
20
+ const { strategy = 'local' } = options;
21
+ if (!authService || typeof authService.getStrategies !== 'function') {
22
+ throw new errors_1.BadRequest('Could not find an authentication service to hash password');
23
+ }
24
+ const [localStrategy] = authService.getStrategies(strategy);
25
+ if (!localStrategy || typeof localStrategy.hashPassword !== 'function') {
26
+ throw new errors_1.BadRequest(`Could not find '${strategy}' strategy to hash password`);
27
+ }
28
+ const addHashedPassword = async (data) => {
29
+ const password = (0, get_1.default)(data, field);
30
+ if (password === undefined) {
31
+ debug(`hook.data.${field} is undefined, not hashing password`);
32
+ return data;
33
+ }
34
+ const hashedPassword = await localStrategy.hashPassword(password, params);
35
+ return (0, set_1.default)((0, cloneDeep_1.default)(data), field, hashedPassword);
36
+ };
37
+ context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) :
38
+ await addHashedPassword(data);
38
39
  }
39
- const [localStrategy] = authService.getStrategies(strategy);
40
- if (!localStrategy || typeof localStrategy.hashPassword !== 'function') {
41
- throw new errors_1.BadRequest(`Could not find '${strategy}' strategy to hash password`);
40
+ if (typeof next === 'function') {
41
+ return next();
42
42
  }
43
- const addHashedPassword = (data) => __awaiter(this, void 0, void 0, function* () {
44
- const password = get_1.default(data, field);
45
- if (password === undefined) {
46
- debug(`hook.data.${field} is undefined, not hashing password`);
47
- return data;
48
- }
49
- const hashedPassword = yield localStrategy.hashPassword(password, params);
50
- return set_1.default(cloneDeep_1.default(data), field, hashedPassword);
51
- });
52
- context.data = Array.isArray(data) ? yield Promise.all(data.map(addHashedPassword)) :
53
- yield addHashedPassword(data);
54
- return context;
55
- });
43
+ };
56
44
  }
57
45
  exports.default = hashPassword;
58
46
  //# sourceMappingURL=hash-password.js.map
@@ -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,kDAA0B;AAI1B,MAAM,KAAK,GAAG,eAAK,CAAC,sDAAsD,CAAC,CAAC;AAO5E,SAAwB,YAAY,CAAE,KAAa,EAAE,UAA+B,EAAE;IACpF,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;IAED,OAAO,CAAO,OAA8B,EAAE,EAAE;QAC9C,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC7B,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;SACvF;QAED,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEtC,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,KAAK,CAAC,qDAAqD,CAAC,CAAC;YAC7D,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,WAAW,GAAG,GAAG,CAAC,qBAAqB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACtE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;QAEvC,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,CAAC,aAAa,KAAK,UA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cAAc,CAAC,CAAC;YACrD,CAAC,CAAA;YAED,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;gBACnF,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;SACjC;QAED,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,OAAO,IAAI,EAAE,CAAC;SACf;IACH,CAAC,CAAC;AACJ,CAAC;AA3CD,+BA2CC"}
@@ -1,3 +1,3 @@
1
- import { HookContext } from '@feathersjs/feathers';
2
- declare const _default: (...fields: string[]) => (context: HookContext<any, any>) => HookContext<any, any>;
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
+ declare const _default: (...fields: string[]) => (context: HookContext, next?: NextFunction) => Promise<void>;
3
3
  export default _default;
@@ -4,33 +4,36 @@ 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
- exports.default = (...fields) => (context) => {
8
- const result = context.dispatch || context.result;
7
+ exports.default = (...fields) => {
9
8
  const o = (current) => {
10
9
  if (typeof current === 'object' && !Array.isArray(current)) {
11
10
  const data = typeof current.toJSON === 'function'
12
11
  ? current.toJSON() : current;
13
- return omit_1.default(data, fields);
12
+ return (0, omit_1.default)(data, fields);
14
13
  }
15
14
  return current;
16
15
  };
17
- if (!result) {
18
- return context;
19
- }
20
- if (Array.isArray(result)) {
21
- context.dispatch = result.map(o);
22
- }
23
- else if (result.data && context.method === 'find') {
24
- context.dispatch = Object.assign({}, result, {
25
- data: result.data.map(o)
26
- });
27
- }
28
- else {
29
- context.dispatch = o(result);
30
- }
31
- if (context.params && context.params.provider) {
32
- context.result = context.dispatch;
33
- }
34
- return context;
16
+ return async (context, next) => {
17
+ if (typeof next === 'function') {
18
+ await next();
19
+ }
20
+ const result = context.dispatch || context.result;
21
+ if (result) {
22
+ if (Array.isArray(result)) {
23
+ context.dispatch = result.map(o);
24
+ }
25
+ else if (result.data && context.method === 'find') {
26
+ context.dispatch = Object.assign({}, result, {
27
+ data: result.data.map(o)
28
+ });
29
+ }
30
+ else {
31
+ context.dispatch = o(result);
32
+ }
33
+ if (context.params && context.params.provider) {
34
+ context.result = context.dispatch;
35
+ }
36
+ }
37
+ };
35
38
  };
36
39
  //# sourceMappingURL=protect.js.map
@@ -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,CAAC,CAAC,OAA8B,EAAE,EAAE;IACzE,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAClD,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,cAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;SAC3B;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAClC;SAAM,IAAI,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;QACnD,OAAO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C,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,MAAM,CAAC,CAAC;aAC9B;YAED,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAC7C,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;aACnC;SACF;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import hashPassword from './hooks/hash-password';
2
2
  export declare const hooks: {
3
3
  hashPassword: typeof hashPassword;
4
- protect: (...fields: string[]) => (context: import("@feathersjs/feathers/lib").HookContext<any, any>) => import("@feathersjs/feathers/lib").HookContext<any, any>;
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>;
5
5
  };
6
6
  export { LocalStrategy } from './strategy';
package/lib/strategy.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,10 +8,10 @@ exports.LocalStrategy = void 0;
17
8
  const bcryptjs_1 = __importDefault(require("bcryptjs"));
18
9
  const get_1 = __importDefault(require("lodash/get"));
19
10
  const omit_1 = __importDefault(require("lodash/omit"));
20
- const debug_1 = __importDefault(require("debug"));
21
11
  const errors_1 = require("@feathersjs/errors");
22
12
  const authentication_1 = require("@feathersjs/authentication");
23
- const debug = debug_1.default('@feathersjs/authentication-local/strategy');
13
+ const commons_1 = require("@feathersjs/commons");
14
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication-local/strategy');
24
15
  class LocalStrategy extends authentication_1.AuthenticationBaseStrategy {
25
16
  verifyConfiguration() {
26
17
  const config = this.configuration;
@@ -33,82 +24,88 @@ class LocalStrategy extends authentication_1.AuthenticationBaseStrategy {
33
24
  get configuration() {
34
25
  const authConfig = this.authentication.configuration;
35
26
  const config = super.configuration || {};
36
- return Object.assign({ hashSize: 10, service: authConfig.service, entity: authConfig.entity, entityId: authConfig.entityId, errorMessage: 'Invalid login', entityPasswordField: config.passwordField, entityUsernameField: config.usernameField }, config);
27
+ return {
28
+ hashSize: 10,
29
+ service: authConfig.service,
30
+ entity: authConfig.entity,
31
+ entityId: authConfig.entityId,
32
+ errorMessage: 'Invalid login',
33
+ entityPasswordField: config.passwordField,
34
+ entityUsernameField: config.usernameField,
35
+ ...config
36
+ };
37
37
  }
38
- getEntityQuery(query, _params) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- return Object.assign({ $limit: 1 }, query);
41
- });
38
+ async getEntityQuery(query, _params) {
39
+ return {
40
+ $limit: 1,
41
+ ...query
42
+ };
42
43
  }
43
- findEntity(username, params) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const { entityUsernameField, errorMessage } = this.configuration;
46
- if (!username) { // don't query for users without any condition set.
47
- throw new errors_1.NotAuthenticated(errorMessage);
48
- }
49
- const query = yield this.getEntityQuery({
50
- [entityUsernameField]: username
51
- }, params);
52
- const findParams = Object.assign({}, params, { query });
53
- const entityService = this.entityService;
54
- debug('Finding entity with query', params.query);
55
- const result = yield entityService.find(findParams);
56
- const list = Array.isArray(result) ? result : result.data;
57
- if (!Array.isArray(list) || list.length === 0) {
58
- debug('No entity found');
59
- throw new errors_1.NotAuthenticated(errorMessage);
60
- }
61
- const [entity] = list;
62
- return entity;
63
- });
44
+ async findEntity(username, params) {
45
+ const { entityUsernameField, errorMessage } = this.configuration;
46
+ if (!username) { // don't query for users without any condition set.
47
+ throw new errors_1.NotAuthenticated(errorMessage);
48
+ }
49
+ const query = await this.getEntityQuery({
50
+ [entityUsernameField]: username
51
+ }, params);
52
+ const findParams = Object.assign({}, params, { query });
53
+ const entityService = this.entityService;
54
+ debug('Finding entity with query', params.query);
55
+ const result = await entityService.find(findParams);
56
+ const list = Array.isArray(result) ? result : result.data;
57
+ if (!Array.isArray(list) || list.length === 0) {
58
+ debug('No entity found');
59
+ throw new errors_1.NotAuthenticated(errorMessage);
60
+ }
61
+ const [entity] = list;
62
+ return entity;
64
63
  }
65
- getEntity(result, params) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const entityService = this.entityService;
68
- const { entityId = entityService.id, entity } = this.configuration;
69
- if (!entityId || result[entityId] === undefined) {
70
- throw new errors_1.NotAuthenticated('Could not get local entity');
71
- }
72
- if (!params.provider) {
73
- return result;
74
- }
75
- return entityService.get(result[entityId], Object.assign(Object.assign({}, params), { [entity]: result }));
64
+ async getEntity(result, params) {
65
+ const entityService = this.entityService;
66
+ const { entityId = entityService.id, entity } = this.configuration;
67
+ if (!entityId || result[entityId] === undefined) {
68
+ throw new errors_1.NotAuthenticated('Could not get local entity');
69
+ }
70
+ if (!params.provider) {
71
+ return result;
72
+ }
73
+ return entityService.get(result[entityId], {
74
+ ...params,
75
+ [entity]: result
76
76
  });
77
77
  }
78
- comparePassword(entity, password) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const { entityPasswordField, errorMessage } = this.configuration;
81
- // find password in entity, this allows for dot notation
82
- const hash = get_1.default(entity, entityPasswordField);
83
- if (!hash) {
84
- debug(`Record is missing the '${entityPasswordField}' password field`);
85
- throw new errors_1.NotAuthenticated(errorMessage);
86
- }
87
- debug('Verifying password');
88
- const result = yield bcryptjs_1.default.compare(password, hash);
89
- if (result) {
90
- return entity;
91
- }
78
+ async comparePassword(entity, password) {
79
+ const { entityPasswordField, errorMessage } = this.configuration;
80
+ // find password in entity, this allows for dot notation
81
+ const hash = (0, get_1.default)(entity, entityPasswordField);
82
+ if (!hash) {
83
+ debug(`Record is missing the '${entityPasswordField}' password field`);
92
84
  throw new errors_1.NotAuthenticated(errorMessage);
93
- });
85
+ }
86
+ debug('Verifying password');
87
+ const result = await bcryptjs_1.default.compare(password, hash);
88
+ if (result) {
89
+ return entity;
90
+ }
91
+ throw new errors_1.NotAuthenticated(errorMessage);
94
92
  }
95
- hashPassword(password, _params) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return bcryptjs_1.default.hash(password, this.configuration.hashSize);
98
- });
93
+ async hashPassword(password, _params) {
94
+ return bcryptjs_1.default.hash(password, this.configuration.hashSize);
99
95
  }
100
- authenticate(data, params) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const { passwordField, usernameField, entity } = this.configuration;
103
- const username = data[usernameField];
104
- const password = data[passwordField];
105
- const result = yield this.findEntity(username, omit_1.default(params, 'provider'));
106
- yield this.comparePassword(result, password);
107
- return {
108
- authentication: { strategy: this.name },
109
- [entity]: yield this.getEntity(result, params)
110
- };
111
- });
96
+ async authenticate(data, params) {
97
+ const { passwordField, usernameField, entity, errorMessage } = this.configuration;
98
+ const username = data[usernameField];
99
+ const password = data[passwordField];
100
+ if (!password) { // exit early if there is no password
101
+ throw new errors_1.NotAuthenticated(errorMessage);
102
+ }
103
+ const result = await this.findEntity(username, (0, omit_1.default)(params, 'provider'));
104
+ await this.comparePassword(result, password);
105
+ return {
106
+ authentication: { strategy: this.name },
107
+ [entity]: await this.getEntity(result, params)
108
+ };
112
109
  }
113
110
  }
114
111
  exports.LocalStrategy = LocalStrategy;
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,wDAA8B;AAC9B,qDAA6B;AAC7B,uDAA+B;AAC/B,kDAA0B;AAC1B,+CAAsD;AAEtD,+DAEoC;AAEpC,MAAM,KAAK,GAAG,eAAK,CAAC,2CAA2C,CAAC,CAAC;AAEjE,MAAa,aAAc,SAAQ,2CAA0B;IAC3D,mBAAmB;QACjB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;QAElC,CAAE,eAAe,EAAE,eAAe,CAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAClD,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE;gBACpC,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,yCAAyC,IAAI,WAAW,CAAC,CAAC;aACxF;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,aAAa;QACf,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;QACrD,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC;QAEzC,uBACE,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,UAAU,CAAC,OAAO,EAC3B,MAAM,EAAE,UAAU,CAAC,MAAM,EACzB,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAC7B,YAAY,EAAE,eAAe,EAC7B,mBAAmB,EAAE,MAAM,CAAC,aAAa,EACzC,mBAAmB,EAAE,MAAM,CAAC,aAAa,IACtC,MAAM,EACT;IACJ,CAAC;IAEK,cAAc,CAAE,KAAY,EAAE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C;QAE5B,MAAM,MAAM,GAAG,MAAM,kBAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEpD,IAAI,MAAM,EAAE;YACV,OAAO,MAAM,CAAC;SACf;QAED,MAAM,IAAI,yBAAgB,CAAC,YAAY,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,YAAY,CAAE,QAAgB,EAAE,OAAe;QACnD,OAAO,kBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,YAAY,CAAE,IAA2B,EAAE,MAAc;QAC7D,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC;QAClF,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,QAAQ,EAAE,EAAE,qCAAqC;YACpD,MAAM,IAAI,yBAAgB,CAAC,YAAY,CAAC,CAAC;SAC1C;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAA,cAAI,EAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;QAEzE,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAE7C,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,CAAC;IACJ,CAAC;CACF;AA7HD,sCA6HC"}
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.2",
4
+ "version": "5.0.0-pre.20",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -16,7 +16,8 @@
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git://github.com/feathersjs/feathers.git"
19
+ "url": "git://github.com/feathersjs/feathers.git",
20
+ "directory": "packages/authentication-local"
20
21
  },
21
22
  "author": {
22
23
  "name": "Feathers contributors",
@@ -42,8 +43,7 @@
42
43
  "scripts": {
43
44
  "prepublish": "npm run compile",
44
45
  "compile": "shx rm -rf lib/ && tsc",
45
- "test": "npm run compile && npm run mocha",
46
- "mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
46
+ "test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
47
47
  },
48
48
  "directories": {
49
49
  "lib": "lib"
@@ -52,24 +52,23 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@feathersjs/authentication": "^5.0.0-pre.2",
56
- "@feathersjs/errors": "^5.0.0-pre.2",
57
- "@feathersjs/feathers": "^5.0.0-pre.2",
55
+ "@feathersjs/authentication": "^5.0.0-pre.20",
56
+ "@feathersjs/commons": "^5.0.0-pre.20",
57
+ "@feathersjs/errors": "^5.0.0-pre.20",
58
+ "@feathersjs/feathers": "^5.0.0-pre.20",
58
59
  "bcryptjs": "^2.4.3",
59
- "debug": "^4.3.1",
60
60
  "lodash": "^4.17.21"
61
61
  },
62
62
  "devDependencies": {
63
- "@feathersjs/adapter-memory": "^5.0.0-pre.2",
63
+ "@feathersjs/memory": "^5.0.0-pre.20",
64
64
  "@types/bcryptjs": "^2.4.2",
65
- "@types/debug": "^4.1.5",
66
- "@types/lodash": "^4.14.168",
67
- "@types/mocha": "^8.2.2",
68
- "@types/node": "^14.14.37",
69
- "mocha": "^8.3.2",
70
- "shx": "^0.3.3",
71
- "ts-node": "^9.1.1",
72
- "typescript": "^4.2.3"
65
+ "@types/lodash": "^4.14.182",
66
+ "@types/mocha": "^9.1.1",
67
+ "@types/node": "^17.0.31",
68
+ "mocha": "^10.0.0",
69
+ "shx": "^0.3.4",
70
+ "ts-node": "^10.7.0",
71
+ "typescript": "^4.6.4"
73
72
  },
74
- "gitHead": "6e1f888dc5b612d2d77653177622e3f66245a0fb"
73
+ "gitHead": "54de749a0b392c7da726c668002b50cafaca530c"
75
74
  }
@@ -2,11 +2,11 @@ import get from 'lodash/get';
2
2
  import set from 'lodash/set';
3
3
  import cloneDeep from 'lodash/cloneDeep';
4
4
  import { BadRequest } from '@feathersjs/errors';
5
- import Debug from 'debug';
6
- import { HookContext } from '@feathersjs/feathers';
5
+ import { createDebug } from '@feathersjs/commons';
6
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
7
7
  import { LocalStrategy } from '../strategy';
8
8
 
9
- const debug = Debug('@feathersjs/authentication-local/hooks/hash-password');
9
+ const debug = createDebug('@feathersjs/authentication-local/hooks/hash-password');
10
10
 
11
11
  export interface HashPasswordOptions {
12
12
  authentication?: string;
@@ -18,47 +18,42 @@ export default function hashPassword (field: string, options: HashPasswordOption
18
18
  throw new Error('The hashPassword hook requires a field name option');
19
19
  }
20
20
 
21
- return async (context: HookContext<any, any>) => {
22
- if (context.type !== 'before') {
23
- throw new Error('The \'hashPassword\' hook should only be used as a \'before\' hook');
24
- }
25
-
21
+ return async (context: HookContext, next?: NextFunction) => {
26
22
  const { app, data, params } = context;
27
23
 
28
- if (data === undefined) {
29
- debug('hook.data is undefined. Skipping hashPassword hook.');
30
- return context;
31
- }
24
+ if (data !== undefined) {
25
+ const authService = app.defaultAuthentication(options.authentication);
26
+ const { strategy = 'local' } = options;
32
27
 
33
- const authService = app.defaultAuthentication(options.authentication);
34
- const { strategy = 'local' } = options;
28
+ if (!authService || typeof authService.getStrategies !== 'function') {
29
+ throw new BadRequest('Could not find an authentication service to hash password');
30
+ }
35
31
 
36
- if (!authService || typeof authService.getStrategies !== 'function') {
37
- throw new BadRequest('Could not find an authentication service to hash password');
38
- }
32
+ const [ localStrategy ] = authService.getStrategies(strategy) as LocalStrategy[];
39
33
 
40
- const [ localStrategy ] = authService.getStrategies(strategy) as LocalStrategy[];
34
+ if (!localStrategy || typeof localStrategy.hashPassword !== 'function') {
35
+ throw new BadRequest(`Could not find '${strategy}' strategy to hash password`);
36
+ }
41
37
 
42
- if (!localStrategy || typeof localStrategy.hashPassword !== 'function') {
43
- throw new BadRequest(`Could not find '${strategy}' strategy to hash password`);
44
- }
38
+ const addHashedPassword = async (data: any) => {
39
+ const password = get(data, field);
45
40
 
46
- const addHashedPassword = async (data: any) => {
47
- const password = get(data, field);
41
+ if (password === undefined) {
42
+ debug(`hook.data.${field} is undefined, not hashing password`);
43
+ return data;
44
+ }
48
45
 
49
- if (password === undefined) {
50
- debug(`hook.data.${field} is undefined, not hashing password`);
51
- return data;
52
- }
46
+ const hashedPassword: string = await localStrategy.hashPassword(password, params);
53
47
 
54
- const hashedPassword: string = await localStrategy.hashPassword(password, params);
48
+ return set(cloneDeep(data), field, hashedPassword);
49
+ }
55
50
 
56
- return set(cloneDeep(data), field, hashedPassword);
51
+ context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) :
52
+ await addHashedPassword(data);
57
53
  }
58
54
 
59
- context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) :
60
- await addHashedPassword(data);
61
-
62
- return context;
55
+ if (typeof next === 'function') {
56
+ return next();
57
+ }
63
58
  };
64
59
  }
@@ -1,8 +1,7 @@
1
1
  import omit from 'lodash/omit';
2
- import { HookContext } from '@feathersjs/feathers';
2
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
3
3
 
4
- export default (...fields: string[]) => (context: HookContext<any, any>) => {
5
- const result = context.dispatch || context.result;
4
+ export default (...fields: string[]) => {
6
5
  const o = (current: any) => {
7
6
  if (typeof current === 'object' && !Array.isArray(current)) {
8
7
  const data = typeof current.toJSON === 'function'
@@ -14,23 +13,27 @@ export default (...fields: string[]) => (context: HookContext<any, any>) => {
14
13
  return current;
15
14
  };
16
15
 
17
- if (!result) {
18
- return context;
19
- }
16
+ return async (context: HookContext, next?: NextFunction) => {
17
+ if (typeof next === 'function') {
18
+ await next();
19
+ }
20
20
 
21
- if (Array.isArray(result)) {
22
- context.dispatch = result.map(o);
23
- } else if (result.data && context.method === 'find') {
24
- context.dispatch = Object.assign({}, result, {
25
- data: result.data.map(o)
26
- });
27
- } else {
28
- context.dispatch = o(result);
29
- }
21
+ const result = context.dispatch || context.result;
30
22
 
31
- if (context.params && context.params.provider) {
32
- context.result = context.dispatch;
33
- }
23
+ if (result) {
24
+ if (Array.isArray(result)) {
25
+ context.dispatch = result.map(o);
26
+ } else if (result.data && context.method === 'find') {
27
+ context.dispatch = Object.assign({}, result, {
28
+ data: result.data.map(o)
29
+ });
30
+ } else {
31
+ context.dispatch = o(result);
32
+ }
34
33
 
35
- return context;
34
+ if (context.params && context.params.provider) {
35
+ context.result = context.dispatch;
36
+ }
37
+ }
38
+ };
36
39
  };
package/src/strategy.ts CHANGED
@@ -2,14 +2,14 @@
2
2
  import bcrypt from 'bcryptjs';
3
3
  import get from 'lodash/get';
4
4
  import omit from 'lodash/omit';
5
- import Debug from 'debug';
6
5
  import { NotAuthenticated } from '@feathersjs/errors';
7
6
  import { Query, Params } from '@feathersjs/feathers';
8
7
  import {
9
8
  AuthenticationRequest, AuthenticationBaseStrategy
10
9
  } from '@feathersjs/authentication';
10
+ import { createDebug } from '@feathersjs/commons';
11
11
 
12
- const debug = Debug('@feathersjs/authentication-local/strategy');
12
+ const debug = createDebug('@feathersjs/authentication-local/strategy');
13
13
 
14
14
  export class LocalStrategy extends AuthenticationBaseStrategy {
15
15
  verifyConfiguration () {
@@ -119,9 +119,14 @@ export class LocalStrategy extends AuthenticationBaseStrategy {
119
119
  }
120
120
 
121
121
  async authenticate (data: AuthenticationRequest, params: Params) {
122
- const { passwordField, usernameField, entity } = this.configuration;
122
+ const { passwordField, usernameField, entity, errorMessage } = this.configuration;
123
123
  const username = data[usernameField];
124
124
  const password = data[passwordField];
125
+
126
+ if (!password) { // exit early if there is no password
127
+ throw new NotAuthenticated(errorMessage);
128
+ }
129
+
125
130
  const result = await this.findEntity(username, omit(params, 'provider'));
126
131
 
127
132
  await this.comparePassword(result, password);