@feathersjs/authentication-local 5.0.0-pre.9 → 5.0.0
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 +163 -215
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/hooks/hash-password.d.ts +8 -1
- package/lib/hooks/hash-password.js +19 -20
- package/lib/hooks/hash-password.js.map +1 -1
- package/lib/hooks/protect.d.ts +5 -1
- package/lib/hooks/protect.js +28 -32
- package/lib/hooks/protect.js.map +1 -1
- package/lib/index.d.ts +15 -2
- package/lib/index.js +20 -3
- package/lib/index.js.map +1 -1
- package/lib/strategy.js +78 -79
- package/lib/strategy.js.map +1 -1
- package/package.json +20 -18
- package/src/hooks/hash-password.ts +36 -28
- package/src/hooks/protect.ts +30 -25
- package/src/index.ts +27 -4
- package/src/strategy.ts +70 -62
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @feathersjs/authentication-local
|
|
2
2
|
|
|
3
3
|
[](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
|
|
4
|
-
[](https://david-dm.org/feathersjs/feathers?path=packages/authentication-local)
|
|
5
4
|
[](https://www.npmjs.com/package/@feathersjs/authentication-local)
|
|
5
|
+
[](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)
|
|
21
|
+
Copyright (c) 2023 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
|
|
22
22
|
|
|
23
23
|
Licensed under the [MIT license](LICENSE).
|
|
@@ -3,4 +3,11 @@ export interface HashPasswordOptions {
|
|
|
3
3
|
authentication?: string;
|
|
4
4
|
strategy?: string;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use Feathers schema resolvers and the `passwordHash` resolver instead
|
|
8
|
+
* @param field
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns
|
|
11
|
+
* @see https://dove.feathersjs.com/api/authentication/local.html#passwordhash
|
|
12
|
+
*/
|
|
13
|
+
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
|
};
|
|
@@ -17,12 +8,19 @@ 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
10
|
const commons_1 = require("@feathersjs/commons");
|
|
20
|
-
const debug = commons_1.createDebug('@feathersjs/authentication-local/hooks/hash-password');
|
|
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
|
+
* @see https://dove.feathersjs.com/api/authentication/local.html#passwordhash
|
|
18
|
+
*/
|
|
21
19
|
function hashPassword(field, options = {}) {
|
|
22
20
|
if (!field) {
|
|
23
21
|
throw new Error('The hashPassword hook requires a field name option');
|
|
24
22
|
}
|
|
25
|
-
return (context, next) =>
|
|
23
|
+
return async (context, next) => {
|
|
26
24
|
const { app, data, params } = context;
|
|
27
25
|
if (data !== undefined) {
|
|
28
26
|
const authService = app.defaultAuthentication(options.authentication);
|
|
@@ -34,22 +32,23 @@ function hashPassword(field, options = {}) {
|
|
|
34
32
|
if (!localStrategy || typeof localStrategy.hashPassword !== 'function') {
|
|
35
33
|
throw new errors_1.BadRequest(`Could not find '${strategy}' strategy to hash password`);
|
|
36
34
|
}
|
|
37
|
-
const addHashedPassword = (data) =>
|
|
38
|
-
const password = get_1.default(data, field);
|
|
35
|
+
const addHashedPassword = async (data) => {
|
|
36
|
+
const password = (0, get_1.default)(data, field);
|
|
39
37
|
if (password === undefined) {
|
|
40
38
|
debug(`hook.data.${field} is undefined, not hashing password`);
|
|
41
39
|
return data;
|
|
42
40
|
}
|
|
43
|
-
const hashedPassword =
|
|
44
|
-
return set_1.default(cloneDeep_1.default(data), field, hashedPassword);
|
|
45
|
-
}
|
|
46
|
-
context.data = Array.isArray(data)
|
|
47
|
-
|
|
41
|
+
const hashedPassword = await localStrategy.hashPassword(password, params);
|
|
42
|
+
return (0, set_1.default)((0, cloneDeep_1.default)(data), field, hashedPassword);
|
|
43
|
+
};
|
|
44
|
+
context.data = Array.isArray(data)
|
|
45
|
+
? await Promise.all(data.map(addHashedPassword))
|
|
46
|
+
: await addHashedPassword(data);
|
|
48
47
|
}
|
|
49
48
|
if (typeof next === 'function') {
|
|
50
|
-
|
|
49
|
+
return next();
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
};
|
|
53
52
|
}
|
|
54
53
|
exports.default = hashPassword;
|
|
55
54
|
//# sourceMappingURL=hash-password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash-password.js","sourceRoot":"","sources":["../../src/hooks/hash-password.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash-password.js","sourceRoot":"","sources":["../../src/hooks/hash-password.ts"],"names":[],"mappings":";;;;;AAAA,qDAA4B;AAC5B,qDAA4B;AAC5B,iEAAwC;AACxC,+CAA+C;AAC/C,iDAAiD;AAIjD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,sDAAsD,CAAC,CAAA;AAOjF;;;;;;GAMG;AACH,SAAwB,YAAY,CAAC,KAAa,EAAE,UAA+B,EAAE;IACnF,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;KACtE;IAED,OAAO,KAAK,EAAE,OAAoB,EAAE,IAAmB,EAAE,EAAE;QACzD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;QAErC,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,MAAM,WAAW,GAAG,GAAG,CAAC,qBAAqB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;YACrE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,OAAO,CAAA;YAEtC,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,CAAC,aAAa,KAAK,UAAU,EAAE;gBACnE,MAAM,IAAI,mBAAU,CAAC,2DAA2D,CAAC,CAAA;aAClF;YAED,MAAM,CAAC,aAAa,CAAC,GAAG,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAoB,CAAA;YAE9E,IAAI,CAAC,aAAa,IAAI,OAAO,aAAa,CAAC,YAAY,KAAK,UAAU,EAAE;gBACtE,MAAM,IAAI,mBAAU,CAAC,mBAAmB,QAAQ,6BAA6B,CAAC,CAAA;aAC/E;YAED,MAAM,iBAAiB,GAAG,KAAK,EAAE,IAAS,EAAE,EAAE;gBAC5C,MAAM,QAAQ,GAAG,IAAA,aAAG,EAAC,IAAI,EAAE,KAAK,CAAC,CAAA;gBAEjC,IAAI,QAAQ,KAAK,SAAS,EAAE;oBAC1B,KAAK,CAAC,aAAa,KAAK,qCAAqC,CAAC,CAAA;oBAC9D,OAAO,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"}
|
package/lib/hooks/protect.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { HookContext, NextFunction } from '@feathersjs/feathers';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated For reliable safe data representations use Feathers schema dispatch resolvers.
|
|
4
|
+
* @see https://dove.feathersjs.comapi/authentication/local.html#protecting-fields
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: (...fields: string[]) => (context: HookContext, next?: NextFunction) => Promise<void>;
|
|
3
7
|
export default _default;
|
package/lib/hooks/protect.js
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
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
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
16
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated For reliable safe data representations use Feathers schema dispatch resolvers.
|
|
9
|
+
* @see https://dove.feathersjs.comapi/authentication/local.html#protecting-fields
|
|
10
|
+
*/
|
|
11
|
+
exports.default = (...fields) => {
|
|
17
12
|
const o = (current) => {
|
|
18
13
|
if (typeof current === 'object' && !Array.isArray(current)) {
|
|
19
|
-
const data = typeof current.toJSON === 'function'
|
|
20
|
-
|
|
21
|
-
return omit_1.default(data, fields);
|
|
14
|
+
const data = typeof current.toJSON === 'function' ? current.toJSON() : current;
|
|
15
|
+
return (0, omit_1.default)(data, fields);
|
|
22
16
|
}
|
|
23
17
|
return current;
|
|
24
18
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const result = context.dispatch || context.result;
|
|
29
|
-
if (result) {
|
|
30
|
-
if (Array.isArray(result)) {
|
|
31
|
-
context.dispatch = result.map(o);
|
|
32
|
-
}
|
|
33
|
-
else if (result.data && context.method === 'find') {
|
|
34
|
-
context.dispatch = Object.assign({}, result, {
|
|
35
|
-
data: result.data.map(o)
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
context.dispatch = o(result);
|
|
19
|
+
return async (context, next) => {
|
|
20
|
+
if (typeof next === 'function') {
|
|
21
|
+
await next();
|
|
40
22
|
}
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
const result = context.dispatch || context.result;
|
|
24
|
+
if (result) {
|
|
25
|
+
if (Array.isArray(result)) {
|
|
26
|
+
context.dispatch = result.map(o);
|
|
27
|
+
}
|
|
28
|
+
else if (result.data && context.method === 'find') {
|
|
29
|
+
context.dispatch = Object.assign({}, result, {
|
|
30
|
+
data: result.data.map(o)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
context.dispatch = o(result);
|
|
35
|
+
}
|
|
36
|
+
if (context.params && context.params.provider) {
|
|
37
|
+
context.result = context.dispatch;
|
|
38
|
+
}
|
|
43
39
|
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
46
42
|
//# sourceMappingURL=protect.js.map
|
package/lib/hooks/protect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../src/hooks/protect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../src/hooks/protect.ts"],"names":[],"mappings":";;;;;AAAA,uDAA8B;AAG9B;;;GAGG;AACH,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,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;YAE9E,OAAO,IAAA,cAAI,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;SAC1B;QAED,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;IAED,OAAO,KAAK,EAAE,OAAoB,EAAE,IAAmB,EAAE,EAAE;QACzD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,MAAM,IAAI,EAAE,CAAA;SACb;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAA;QAEjD,IAAI,MAAM,EAAE;YACV,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACzB,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;aACjC;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,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
|
|
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 }
|
|
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,27 @@ 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
|
-
|
|
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
|
+
if (value === undefined) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
const { app, params } = context;
|
|
24
|
+
const authService = app.defaultAuthentication(options.service);
|
|
25
|
+
const localStrategy = authService.getStrategy(options.strategy);
|
|
26
|
+
return localStrategy.hashPassword(value, params);
|
|
27
|
+
};
|
|
28
|
+
exports.passwordHash = passwordHash;
|
|
12
29
|
//# 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":";;;;;;
|
|
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,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAO,KAAK,CAAA;KACb;IAED,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;AAZU,QAAA,YAAY,gBAYtB"}
|
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
|
};
|
|
@@ -20,11 +11,11 @@ const omit_1 = __importDefault(require("lodash/omit"));
|
|
|
20
11
|
const errors_1 = require("@feathersjs/errors");
|
|
21
12
|
const authentication_1 = require("@feathersjs/authentication");
|
|
22
13
|
const commons_1 = require("@feathersjs/commons");
|
|
23
|
-
const debug = commons_1.createDebug('@feathersjs/authentication-local/strategy');
|
|
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;
|
|
27
|
-
['usernameField', 'passwordField'].forEach(prop => {
|
|
18
|
+
['usernameField', 'passwordField'].forEach((prop) => {
|
|
28
19
|
if (typeof config[prop] !== 'string') {
|
|
29
20
|
throw new Error(`'${this.name}' authentication strategy requires a '${prop}' setting`);
|
|
30
21
|
}
|
|
@@ -33,82 +24,90 @@ 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
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
async getEntityQuery(query, _params) {
|
|
39
|
+
return {
|
|
40
|
+
$limit: 1,
|
|
41
|
+
...query
|
|
42
|
+
};
|
|
42
43
|
}
|
|
43
|
-
findEntity(username, params) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
44
|
+
async findEntity(username, params) {
|
|
45
|
+
const { entityUsernameField, errorMessage } = this.configuration;
|
|
46
|
+
if (!username) {
|
|
47
|
+
// don't query for users without any condition set.
|
|
48
|
+
throw new errors_1.NotAuthenticated(errorMessage);
|
|
49
|
+
}
|
|
50
|
+
const query = await this.getEntityQuery({
|
|
51
|
+
[entityUsernameField]: username
|
|
52
|
+
}, params);
|
|
53
|
+
const findParams = Object.assign({}, params, { query });
|
|
54
|
+
const entityService = this.entityService;
|
|
55
|
+
debug('Finding entity with query', params.query);
|
|
56
|
+
const result = await entityService.find(findParams);
|
|
57
|
+
const list = Array.isArray(result) ? result : result.data;
|
|
58
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
59
|
+
debug('No entity found');
|
|
60
|
+
throw new errors_1.NotAuthenticated(errorMessage);
|
|
61
|
+
}
|
|
62
|
+
const [entity] = list;
|
|
63
|
+
return entity;
|
|
64
64
|
}
|
|
65
|
-
getEntity(result, params) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
async getEntity(result, params) {
|
|
66
|
+
const entityService = this.entityService;
|
|
67
|
+
const { entityId = entityService.id, entity } = this.configuration;
|
|
68
|
+
if (!entityId || result[entityId] === undefined) {
|
|
69
|
+
throw new errors_1.NotAuthenticated('Could not get local entity');
|
|
70
|
+
}
|
|
71
|
+
if (!params.provider) {
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
return entityService.get(result[entityId], {
|
|
75
|
+
...params,
|
|
76
|
+
[entity]: result
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
|
-
comparePassword(entity, password) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
}
|
|
79
|
+
async comparePassword(entity, password) {
|
|
80
|
+
const { entityPasswordField, errorMessage } = this.configuration;
|
|
81
|
+
// find password in entity, this allows for dot notation
|
|
82
|
+
const hash = (0, get_1.default)(entity, entityPasswordField);
|
|
83
|
+
if (!hash) {
|
|
84
|
+
debug(`Record is missing the '${entityPasswordField}' password field`);
|
|
92
85
|
throw new errors_1.NotAuthenticated(errorMessage);
|
|
93
|
-
}
|
|
86
|
+
}
|
|
87
|
+
debug('Verifying password');
|
|
88
|
+
const result = await bcryptjs_1.default.compare(password, hash);
|
|
89
|
+
if (result) {
|
|
90
|
+
return entity;
|
|
91
|
+
}
|
|
92
|
+
throw new errors_1.NotAuthenticated(errorMessage);
|
|
94
93
|
}
|
|
95
|
-
hashPassword(password, _params) {
|
|
96
|
-
return
|
|
97
|
-
return bcryptjs_1.default.hash(password, this.configuration.hashSize);
|
|
98
|
-
});
|
|
94
|
+
async hashPassword(password, _params) {
|
|
95
|
+
return bcryptjs_1.default.hash(password, this.configuration.hashSize);
|
|
99
96
|
}
|
|
100
|
-
authenticate(data, params) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
async authenticate(data, params) {
|
|
98
|
+
const { passwordField, usernameField, entity, errorMessage } = this.configuration;
|
|
99
|
+
const username = data[usernameField];
|
|
100
|
+
const password = data[passwordField];
|
|
101
|
+
if (!password) {
|
|
102
|
+
// exit early if there is no password
|
|
103
|
+
throw new errors_1.NotAuthenticated(errorMessage);
|
|
104
|
+
}
|
|
105
|
+
const result = await this.findEntity(username, (0, omit_1.default)(params, 'provider'));
|
|
106
|
+
await this.comparePassword(result, password);
|
|
107
|
+
return {
|
|
108
|
+
authentication: { strategy: this.name },
|
|
109
|
+
[entity]: await this.getEntity(result, params)
|
|
110
|
+
};
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
exports.LocalStrategy = LocalStrategy;
|
package/lib/strategy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAsD;AACtD,wDAA6B;AAC7B,qDAA4B;AAC5B,uDAA8B;AAC9B,+CAAqD;AAErD,+DAA8F;AAC9F,iDAAiD;AAEjD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,2CAA2C,CAAC,CAAA;AAEtE,MAAa,aAAc,SAAQ,2CAA0B;IAC3D,mBAAmB;QACjB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAEhC;QAAA,CAAC,eAAe,EAAE,eAAe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AAE,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
|
|
4
|
+
"version": "5.0.0",
|
|
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",
|
|
@@ -41,9 +42,9 @@
|
|
|
41
42
|
],
|
|
42
43
|
"scripts": {
|
|
43
44
|
"prepublish": "npm run compile",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
46
|
+
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
47
|
+
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
|
|
47
48
|
},
|
|
48
49
|
"directories": {
|
|
49
50
|
"lib": "lib"
|
|
@@ -52,23 +53,24 @@
|
|
|
52
53
|
"access": "public"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@feathersjs/authentication": "^5.0.0
|
|
56
|
-
"@feathersjs/commons": "^5.0.0
|
|
57
|
-
"@feathersjs/errors": "^5.0.0
|
|
58
|
-
"@feathersjs/feathers": "^5.0.0
|
|
56
|
+
"@feathersjs/authentication": "^5.0.0",
|
|
57
|
+
"@feathersjs/commons": "^5.0.0",
|
|
58
|
+
"@feathersjs/errors": "^5.0.0",
|
|
59
|
+
"@feathersjs/feathers": "^5.0.0",
|
|
59
60
|
"bcryptjs": "^2.4.3",
|
|
60
61
|
"lodash": "^4.17.21"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
|
-
"@feathersjs/memory": "^5.0.0
|
|
64
|
+
"@feathersjs/memory": "^5.0.0",
|
|
65
|
+
"@feathersjs/schema": "^5.0.0",
|
|
64
66
|
"@types/bcryptjs": "^2.4.2",
|
|
65
|
-
"@types/lodash": "^4.14.
|
|
66
|
-
"@types/mocha": "^
|
|
67
|
-
"@types/node": "^
|
|
68
|
-
"mocha": "^
|
|
69
|
-
"shx": "^0.3.
|
|
70
|
-
"ts-node": "^10.1
|
|
71
|
-
"typescript": "^4.
|
|
67
|
+
"@types/lodash": "^4.14.191",
|
|
68
|
+
"@types/mocha": "^10.0.1",
|
|
69
|
+
"@types/node": "^18.14.1",
|
|
70
|
+
"mocha": "^10.2.0",
|
|
71
|
+
"shx": "^0.3.4",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"typescript": "^4.9.5"
|
|
72
74
|
},
|
|
73
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "90caf635aec850550b9d37bea2762af959d9e8d5"
|
|
74
76
|
}
|