@riao/authn-password 1.0.0 → 1.1.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/README.md +4 -1
- package/authentication-password-migrations.d.ts +4 -3
- package/authentication-password-migrations.js +4 -3
- package/authentication-password-migrations.js.map +1 -1
- package/authentication-password.d.ts +3 -0
- package/authentication-password.js +25 -6
- package/authentication-password.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,10 +67,13 @@ const userId = await authService.createPrincipal({
|
|
|
67
67
|
password: 'securePassword123',
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
// Change a password
|
|
71
|
+
await authService.changePassword(userId, 'newPassword123');
|
|
72
|
+
|
|
70
73
|
// Authenticate a user
|
|
71
74
|
const user = await authService.authenticate({
|
|
72
75
|
login: 'john.doe',
|
|
73
|
-
password: '
|
|
76
|
+
password: 'newPassword123',
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
if (user) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Migration } from '@riao/dbal';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Migration, MigrationPackage } from '@riao/dbal';
|
|
2
|
+
export declare class AuthenticationPasswordMigrations extends MigrationPackage {
|
|
3
|
+
package: string;
|
|
4
|
+
name: string;
|
|
4
5
|
getMigrations(): Promise<Record<string, typeof Migration<any>>>;
|
|
5
6
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthenticationPasswordMigrations = void 0;
|
|
4
|
-
const
|
|
4
|
+
const dbal_1 = require("@riao/dbal");
|
|
5
5
|
const _001_create_passwords_table_1 = require("./migrations/001-create-passwords-table");
|
|
6
|
-
class AuthenticationPasswordMigrations extends
|
|
6
|
+
class AuthenticationPasswordMigrations extends dbal_1.MigrationPackage {
|
|
7
|
+
package = '@riao/iam-authn-password';
|
|
8
|
+
name = '@riao/iam-authn-password';
|
|
7
9
|
async getMigrations() {
|
|
8
10
|
return {
|
|
9
|
-
...(await super.getMigrations()),
|
|
10
11
|
'create-passwords-table': _001_create_passwords_table_1.CreatePasswordsTable,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-password-migrations.js","sourceRoot":"","sources":["../../src/authentication-password-migrations.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"authentication-password-migrations.js","sourceRoot":"","sources":["../../src/authentication-password-migrations.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AACzD,yFAA+E;AAE/E,MAAa,gCAAiC,SAAQ,uBAAgB;IAC5D,OAAO,GAAG,0BAA0B,CAAC;IACrC,IAAI,GAAG,0BAA0B,CAAC;IAElC,KAAK,CAAC,aAAa;QAI3B,OAAO;YACN,wBAAwB,EAAE,kDAAoB;SAC9C,CAAC;IACH,CAAC;CACD;AAZD,4EAYC"}
|
|
@@ -14,7 +14,10 @@ export declare abstract class PasswordAuthentication<TPrincipal extends Principa
|
|
|
14
14
|
createPrincipal(principal: Omit<TPrincipal, 'id' | 'create_timestamp'> & {
|
|
15
15
|
password: string;
|
|
16
16
|
}): Promise<DatabaseRecordId>;
|
|
17
|
+
changePassword(principalId: DatabaseRecordId, newPassword: string): Promise<void>;
|
|
17
18
|
authenticate(credentials: Partial<TPrincipal & {
|
|
18
19
|
password: string;
|
|
19
20
|
}>): Promise<TPrincipal | null>;
|
|
21
|
+
protected revokePasswords(principalId: DatabaseRecordId): Promise<void>;
|
|
22
|
+
protected insertPassword(principalId: DatabaseRecordId, hash: string): Promise<void>;
|
|
20
23
|
}
|
|
@@ -18,14 +18,16 @@ class PasswordAuthentication extends authentication_1.Authentication {
|
|
|
18
18
|
const hash = await this.hash.make(principal.password);
|
|
19
19
|
delete principal.password;
|
|
20
20
|
const principalId = await super.createPrincipal(principal);
|
|
21
|
-
await this.
|
|
22
|
-
record: {
|
|
23
|
-
principal_id: principalId,
|
|
24
|
-
password_hash: hash,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
21
|
+
await this.insertPassword(principalId, hash);
|
|
27
22
|
return principalId;
|
|
28
23
|
}
|
|
24
|
+
async changePassword(principalId, newPassword) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.log('Changing password for principal ID:', principalId, newPassword);
|
|
27
|
+
const hash = await this.hash.make(newPassword);
|
|
28
|
+
await this.revokePasswords(principalId);
|
|
29
|
+
await this.insertPassword(principalId, hash);
|
|
30
|
+
}
|
|
29
31
|
async authenticate(credentials) {
|
|
30
32
|
const principal = await this.findActivePrincipal({
|
|
31
33
|
where: {
|
|
@@ -45,6 +47,23 @@ class PasswordAuthentication extends authentication_1.Authentication {
|
|
|
45
47
|
const isValid = await this.hash.check(credentials.password, passwordRecord?.password_hash);
|
|
46
48
|
return isValid ? principal : null;
|
|
47
49
|
}
|
|
50
|
+
async revokePasswords(principalId) {
|
|
51
|
+
await this.passwordsRepo.update({
|
|
52
|
+
set: { deactivate_timestamp: new Date() },
|
|
53
|
+
where: {
|
|
54
|
+
principal_id: principalId,
|
|
55
|
+
deactivate_timestamp: null,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async insertPassword(principalId, hash) {
|
|
60
|
+
await this.passwordsRepo.insertOne({
|
|
61
|
+
record: {
|
|
62
|
+
principal_id: principalId,
|
|
63
|
+
password_hash: hash,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
48
67
|
}
|
|
49
68
|
exports.PasswordAuthentication = PasswordAuthentication;
|
|
50
69
|
//# sourceMappingURL=authentication-password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-password.js","sourceRoot":"","sources":["../../src/authentication-password.ts"],"names":[],"mappings":";;;AACA,yCAAsC;AAEtC,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AAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACnC,CAAC;IAES,KAAK,CAAC,eAAe,CAC9B,WAA6B;QAE7B,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;YAC/B,GAAG,EAAE,EAAE,oBAAoB,EAAE,IAAI,IAAI,EAAE,EAAE;YACzC,KAAK,EAAE;gBACN,YAAY,EAAE,WAAqB;gBACnC,oBAAoB,EAAE,IAAI;aAC1B;SACD,CAAC,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,cAAc,CAC7B,WAA6B,EAC7B,IAAY;QAEZ,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC;YAClC,MAAM,EAAE;gBACP,YAAY,EAAE,WAAqB;gBACnC,aAAa,EAAE,IAAI;aACnB;SACD,CAAC,CAAC;IACJ,CAAC;CACD;AAnGD,wDAmGC"}
|
package/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { PasswordAuthentication } from './authentication-password';
|
|
1
|
+
export { PasswordAuthentication, PasswordAuthenticationOptions, } from './authentication-password';
|
|
2
|
+
export * from './password';
|
package/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PasswordAuthentication = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
var authentication_password_1 = require("./authentication-password");
|
|
5
6
|
Object.defineProperty(exports, "PasswordAuthentication", { enumerable: true, get: function () { return authentication_password_1.PasswordAuthentication; } });
|
|
7
|
+
tslib_1.__exportStar(require("./password"), exports);
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/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":";;;;AAAA,qEAGmC;AAFlC,iIAAA,sBAAsB,OAAA;AAGvB,qDAA2B"}
|