@furystack/security 6.0.1 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/helpers.d.ts.map +1 -1
- package/esm/helpers.js +3 -1
- package/esm/helpers.js.map +1 -1
- package/esm/password-authenticator.d.ts +1 -1
- package/esm/password-authenticator.d.ts.map +1 -1
- package/esm/password-authenticator.js +8 -4
- package/esm/password-authenticator.js.map +1 -1
- package/package.json +7 -7
- package/src/helpers.ts +5 -1
- package/src/password-authenticator.ts +9 -5
package/esm/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,aAAc,QAAQ,WAAW,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,aAAc,QAAQ,WAAW,OAAO,CAAC,cAAc,CAAC,SAQrF,CAAA"}
|
package/esm/helpers.js
CHANGED
|
@@ -6,7 +6,9 @@ import { SecurityPolicy } from './security-policy.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export const usePasswordPolicy = (injector, policy) => {
|
|
8
8
|
const plainPolicy = new SecurityPolicy();
|
|
9
|
-
|
|
9
|
+
if (policy) {
|
|
10
|
+
Object.assign(plainPolicy, policy);
|
|
11
|
+
}
|
|
10
12
|
injector.setExplicitInstance(plainPolicy, SecurityPolicy);
|
|
11
13
|
};
|
|
12
14
|
//# sourceMappingURL=helpers.js.map
|
package/esm/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAAE,MAAgC,EAAE,EAAE;IACxF,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAAE,MAAgC,EAAE,EAAE;IACxF,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAA;IAExC,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACpC,CAAC;IAED,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;AAC3D,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SecurityPolicyManager } from './security-policy-manager.js';
|
|
2
1
|
import type { PasswordCheckResult } from './models/index.js';
|
|
3
2
|
import type { PasswordHasher } from './password-hasher.js';
|
|
3
|
+
import { SecurityPolicyManager } from './security-policy-manager.js';
|
|
4
4
|
export declare class PasswordAuthenticator {
|
|
5
5
|
private readonly passwordStore;
|
|
6
6
|
private readonly tokenStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-authenticator.d.ts","sourceRoot":"","sources":["../src/password-authenticator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password-authenticator.d.ts","sourceRoot":"","sources":["../src/password-authenticator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAEpE,qBACa,qBAAqB;IAChC,iBACyB,aAAa,CAA+C;IAErF,iBACyB,UAAU,CAA4C;IAE/E,SAGwB,MAAM,EAAE,cAAc,CAAA;IAE9C;;;;OAIG;IACU,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkBxG;;;;;;OAMG;IACU,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB7G;;;;OAIG;IACU,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B5E,aAAa,EAAE,qBAAqB,CAAA;CACpD"}
|
|
@@ -9,10 +9,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { StoreManager } from '@furystack/core';
|
|
11
11
|
import { Injectable, Injected } from '@furystack/inject';
|
|
12
|
-
import { SecurityPolicyManager } from './security-policy-manager.js';
|
|
13
12
|
import { UnauthenticatedError } from './errors/index.js';
|
|
14
|
-
import { PasswordCredential, PasswordResetToken } from './models/index.js';
|
|
15
13
|
import { PasswordComplexityError } from './errors/password-complexity-error.js';
|
|
14
|
+
import { PasswordCredential, PasswordResetToken } from './models/index.js';
|
|
15
|
+
import { SecurityPolicyManager } from './security-policy-manager.js';
|
|
16
16
|
let PasswordAuthenticator = class PasswordAuthenticator {
|
|
17
17
|
/**
|
|
18
18
|
* @param userName The User's unique name
|
|
@@ -54,7 +54,9 @@ let PasswordAuthenticator = class PasswordAuthenticator {
|
|
|
54
54
|
}
|
|
55
55
|
const newCredential = await this.hasher.createCredential(userName, plainPassword);
|
|
56
56
|
const existing = await this.passwordStore.get(userName);
|
|
57
|
-
|
|
57
|
+
if (existing) {
|
|
58
|
+
await this.passwordStore.remove(existing.userName);
|
|
59
|
+
}
|
|
58
60
|
await this.passwordStore.add(newCredential);
|
|
59
61
|
}
|
|
60
62
|
/**
|
|
@@ -77,7 +79,9 @@ let PasswordAuthenticator = class PasswordAuthenticator {
|
|
|
77
79
|
}
|
|
78
80
|
const newCredential = await this.hasher.createCredential(token.userName, plainPassword);
|
|
79
81
|
const existing = await this.passwordStore.get(token.userName);
|
|
80
|
-
|
|
82
|
+
if (existing) {
|
|
83
|
+
await this.passwordStore.remove(existing.userName);
|
|
84
|
+
}
|
|
81
85
|
await this.passwordStore.add(newCredential);
|
|
82
86
|
}
|
|
83
87
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-authenticator.js","sourceRoot":"","sources":["../src/password-authenticator.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"password-authenticator.js","sourceRoot":"","sources":["../src/password-authenticator.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAE/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE1E,OAAO,EAAE,qBAAqB,EA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,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACpD,CAAC;QACD,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAC7C,CAAC;CAIF,CAAA;AA1F0B;IADxB,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;;4DAClB;AAG5D;IADxB,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;;yDACrB;AAKvD;IAHvB,QAAQ,CAAC,UAAuC,QAAQ;QACvD,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC/D,CAAC,CAAC;;qDAC4C;AAiF/B;IADd,QAAQ,CAAC,qBAAqB,CAAC;8BACF,qBAAqB;4DAAA;AA3FxC,qBAAqB;IADjC,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,qBAAqB,CA4FjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/security",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "Security, password management and authorization related stuff for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"url": "https://github.com/furystack/furystack/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@furystack/core": "^15.0.
|
|
39
|
-
"@furystack/inject": "^12.0.
|
|
38
|
+
"@furystack/core": "^15.0.3",
|
|
39
|
+
"@furystack/inject": "^12.0.2"
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/furystack/furystack",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@furystack/utils": "^8.0.
|
|
44
|
-
"@types/node": "^
|
|
45
|
-
"typescript": "^5.5.
|
|
46
|
-
"vitest": "^2.0.
|
|
43
|
+
"@furystack/utils": "^8.0.2",
|
|
44
|
+
"@types/node": "^22.3.0",
|
|
45
|
+
"typescript": "^5.5.4",
|
|
46
|
+
"vitest": "^2.0.5"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/helpers.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { SecurityPolicy } from './security-policy.js'
|
|
|
8
8
|
*/
|
|
9
9
|
export const usePasswordPolicy = (injector: Injector, policy?: Partial<SecurityPolicy>) => {
|
|
10
10
|
const plainPolicy = new SecurityPolicy()
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
if (policy) {
|
|
13
|
+
Object.assign(plainPolicy, policy)
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
injector.setExplicitInstance(plainPolicy, SecurityPolicy)
|
|
13
17
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { PhysicalStore } from '@furystack/core'
|
|
2
2
|
import { StoreManager } from '@furystack/core'
|
|
3
3
|
import { Injectable, Injected } from '@furystack/inject'
|
|
4
|
-
import { SecurityPolicyManager } from './security-policy-manager.js'
|
|
5
4
|
import { UnauthenticatedError } from './errors/index.js'
|
|
5
|
+
import { PasswordComplexityError } from './errors/password-complexity-error.js'
|
|
6
6
|
import type { PasswordCheckResult } from './models/index.js'
|
|
7
7
|
import { PasswordCredential, PasswordResetToken } from './models/index.js'
|
|
8
|
-
import { PasswordComplexityError } from './errors/password-complexity-error.js'
|
|
9
8
|
import type { PasswordHasher } from './password-hasher.js'
|
|
9
|
+
import { SecurityPolicyManager } from './security-policy-manager.js'
|
|
10
10
|
|
|
11
11
|
@Injectable({ lifetime: 'singleton' })
|
|
12
12
|
export class PasswordAuthenticator {
|
|
@@ -14,7 +14,7 @@ export class PasswordAuthenticator {
|
|
|
14
14
|
private declare readonly passwordStore: PhysicalStore<PasswordCredential, 'userName'>
|
|
15
15
|
|
|
16
16
|
@Injected((injector) => injector.getInstance(StoreManager).getStoreFor(PasswordResetToken, 'token'))
|
|
17
|
-
private declare readonly tokenStore
|
|
17
|
+
private declare readonly tokenStore: PhysicalStore<PasswordResetToken, 'token'>
|
|
18
18
|
|
|
19
19
|
@Injected(function (this: PasswordAuthenticator, injector) {
|
|
20
20
|
return injector.getInstance(this.policyManager.policy.hasher)
|
|
@@ -63,7 +63,9 @@ export class PasswordAuthenticator {
|
|
|
63
63
|
}
|
|
64
64
|
const newCredential = await this.hasher.createCredential(userName, plainPassword)
|
|
65
65
|
const existing = await this.passwordStore.get(userName)
|
|
66
|
-
|
|
66
|
+
if (existing) {
|
|
67
|
+
await this.passwordStore.remove(existing.userName)
|
|
68
|
+
}
|
|
67
69
|
await this.passwordStore.add(newCredential)
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -91,7 +93,9 @@ export class PasswordAuthenticator {
|
|
|
91
93
|
|
|
92
94
|
const newCredential = await this.hasher.createCredential(token.userName, plainPassword)
|
|
93
95
|
const existing = await this.passwordStore.get(token.userName)
|
|
94
|
-
|
|
96
|
+
if (existing) {
|
|
97
|
+
await this.passwordStore.remove(existing.userName)
|
|
98
|
+
}
|
|
95
99
|
await this.passwordStore.add(newCredential)
|
|
96
100
|
}
|
|
97
101
|
|