@hapiboo/module-auth 1.2.2 → 1.4.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/dist/models/credential.js +2 -2
- package/dist/router/controller.d.ts +3 -0
- package/dist/router/controller.js +4 -0
- package/dist/router/init.js +3 -0
- package/dist/service/authentication.d.ts +3 -0
- package/dist/service/authentication.js +69 -53
- package/dist/service/authorization.js +3 -2
- package/dist/service/settings.d.ts +10 -6
- package/dist/service/settings.js +34 -14
- package/package.json +1 -1
|
@@ -202,8 +202,8 @@ class Password {
|
|
|
202
202
|
return this.hash === this.getHash(base64password);
|
|
203
203
|
}
|
|
204
204
|
setPassword(base64Password) {
|
|
205
|
-
this.length = settings_1.authSettings.passwordHashLength;
|
|
206
|
-
this.iterations = settings_1.authSettings.passwordHashIterations;
|
|
205
|
+
this.length = settings_1.authSettings.passwordHashLength();
|
|
206
|
+
this.iterations = settings_1.authSettings.passwordHashIterations();
|
|
207
207
|
this.salt = crypto_1.cryptoProvider.generateSalt(this.length);
|
|
208
208
|
this.hash = this.getHash(base64Password);
|
|
209
209
|
this.lastChangedAt = date_1.DateObject.now().toUtc();
|
|
@@ -12,6 +12,10 @@ var authController;
|
|
|
12
12
|
return authentication_1.authenticationService.general.initData(process.env.FRONTEND_URL);
|
|
13
13
|
}
|
|
14
14
|
init.start = start;
|
|
15
|
+
function testMode() {
|
|
16
|
+
return authentication_1.authenticationService.general.testMode();
|
|
17
|
+
}
|
|
18
|
+
init.testMode = testMode;
|
|
15
19
|
})(init = authController.init || (authController.init = {}));
|
|
16
20
|
let user;
|
|
17
21
|
(function (user) {
|
package/dist/router/init.js
CHANGED
|
@@ -8,4 +8,7 @@ const router = (0, express_1.Router)();
|
|
|
8
8
|
router.put('', async (_request, response) => {
|
|
9
9
|
server_1.server.prepareJsonPromiseResponse(response, controller_1.authController.init.start());
|
|
10
10
|
});
|
|
11
|
+
router.post('/test', async (_request, response) => {
|
|
12
|
+
server_1.server.prepareJsonPromiseResponse(response, controller_1.authController.init.testMode());
|
|
13
|
+
});
|
|
11
14
|
exports.init = server_1.routingProvider.createRoutingItem('/init', router);
|
|
@@ -6,6 +6,9 @@ export declare namespace authenticationService {
|
|
|
6
6
|
function initData(baseURL: string): IResponsePromise<{
|
|
7
7
|
id: string;
|
|
8
8
|
}>;
|
|
9
|
+
function testMode(): IResponsePromise<{
|
|
10
|
+
testMode: boolean;
|
|
11
|
+
}>;
|
|
9
12
|
function get(user_id: string): IResponsePromise<User>;
|
|
10
13
|
}
|
|
11
14
|
namespace me {
|
|
@@ -78,64 +78,73 @@ var helper;
|
|
|
78
78
|
(function (users) {
|
|
79
79
|
function registerPassword(display, email, credentialName, password, admin, isInvited, account_id, baseUrl) {
|
|
80
80
|
return core_1.promise.createPromise((resolve, reject) => {
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
//let's check if we could move forward with current settings
|
|
82
|
+
if (!isInvited && !settings_1.authSettings.allowSelfRegistration()) {
|
|
83
|
+
reject(core_1.ResponseError.getMessageResponse(403, 'Self registration is not allowed.'));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
//we need to find out if credentialName is not used
|
|
87
|
+
core_1.promise.check(searchPassword(credentialName, true), reject)
|
|
88
|
+
.then((value) => {
|
|
89
|
+
if (value.found) {
|
|
90
|
+
reject(core_1.ResponseError.getMessageResponse(409, 'credential name already registered'));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (display && email && credentialName) {
|
|
94
|
+
//let's create actual user data
|
|
95
|
+
const user_id = (0, uuid_1.v4)();
|
|
96
|
+
let invite = undefined;
|
|
97
|
+
let confirm = (0, uuid_1.v4)().substring(0, 6).toUpperCase();
|
|
98
|
+
if (settings_1.authSettings.allowTestMode() && settings_1.authSettings.testMode()) {
|
|
99
|
+
confirm = 'M6K513';
|
|
100
|
+
}
|
|
101
|
+
if (isInvited) {
|
|
102
|
+
invite = confirm;
|
|
103
|
+
confirm = undefined;
|
|
104
|
+
password = '';
|
|
105
|
+
}
|
|
106
|
+
core_1.promise.check(repository_1.repository.credential.create(new models_1.Credential().createPassword((0, uuid_1.v4)(), credentialName, user_id, 'pending', password, confirm, invite)), reject)
|
|
107
|
+
.then((cred) => {
|
|
108
|
+
//now, create user
|
|
109
|
+
core_1.promise.check(repository_1.repository.user.create(new models_1.User().create(user_id, account_id, admin ? 'admin' : 'standard', 'created', display, email)), reject)
|
|
110
|
+
.then((dataItem) => {
|
|
111
|
+
//and send the code to confirm
|
|
112
|
+
emails.confirm(email, display, isInvited, isInvited ? cred.invite : cred.confirmation, baseUrl)
|
|
111
113
|
.then(() => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
reject(core_1.ResponseError.getCollectionResponse([reason, reasonCred]));
|
|
118
|
-
});
|
|
119
|
-
}).catch((reasonUser) => {
|
|
120
|
-
//despite error, let's try to clean up other data
|
|
121
|
-
repository_1.repository.credential.remove(cred.id)
|
|
114
|
+
resolve({ user: dataItem, credentials: cred });
|
|
115
|
+
}).catch((reason) => {
|
|
116
|
+
console.error(reason.message);
|
|
117
|
+
//in case of error, we need to remove all created data
|
|
118
|
+
repository_1.repository.user.remove(dataItem.id)
|
|
122
119
|
.then(() => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
repository_1.repository.credential.remove(cred.id)
|
|
121
|
+
.then(() => {
|
|
122
|
+
reject(reason);
|
|
123
|
+
}).catch((reasonCred) => {
|
|
124
|
+
//we have 2 errors, and needs to combine them
|
|
125
|
+
reject(core_1.ResponseError.getCollectionResponse([reason, reasonCred]));
|
|
126
|
+
});
|
|
127
|
+
}).catch((reasonUser) => {
|
|
128
|
+
//despite error, let's try to clean up other data
|
|
129
|
+
repository_1.repository.credential.remove(cred.id)
|
|
130
|
+
.then(() => {
|
|
131
|
+
//we have 2 errors, and needs to combine them
|
|
132
|
+
reject(core_1.ResponseError.getCollectionResponse([reason, reasonUser]));
|
|
133
|
+
}).catch((reasonCred) => {
|
|
134
|
+
//we have 3 errors, and needs to combine them
|
|
135
|
+
reject(core_1.ResponseError.getCollectionResponse([reason, reasonUser, reasonCred]));
|
|
136
|
+
});
|
|
128
137
|
});
|
|
129
138
|
});
|
|
130
139
|
});
|
|
131
140
|
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
reject(core_1.ResponseError.getMessageResponse(400, 'data is not valid'));
|
|
144
|
+
}
|
|
136
145
|
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
139
148
|
});
|
|
140
149
|
}
|
|
141
150
|
users.registerPassword = registerPassword;
|
|
@@ -217,8 +226,9 @@ var authenticationService;
|
|
|
217
226
|
core_1.promise.checkVoid(authorization_1.authorizationService.general.initializeSecurityModel(), reject)
|
|
218
227
|
.then(() => {
|
|
219
228
|
//create first admin
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
const to_create = settings_1.authSettings.firstAdmin();
|
|
230
|
+
console.info('... creating first admin user: ' + to_create.email);
|
|
231
|
+
core_1.promise.resolve(admin.invite(to_create.email, to_create.email, to_create.name, baseURL), resolve, reject);
|
|
222
232
|
});
|
|
223
233
|
}
|
|
224
234
|
else {
|
|
@@ -228,6 +238,12 @@ var authenticationService;
|
|
|
228
238
|
});
|
|
229
239
|
}
|
|
230
240
|
general.initData = initData;
|
|
241
|
+
function testMode() {
|
|
242
|
+
return core_1.promise.createDelayedPromise((resolve, _reject) => {
|
|
243
|
+
resolve({ testMode: settings_1.authSettings.changeTestMode() });
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
general.testMode = testMode;
|
|
231
247
|
function get(user_id) {
|
|
232
248
|
return repository_1.repository.user.getById(user_id);
|
|
233
249
|
}
|
|
@@ -17,8 +17,9 @@ var authorizationValidator;
|
|
|
17
17
|
function checkUserPermission(user_id, permission_id) {
|
|
18
18
|
if (userPermissionCache.has(user_id)) {
|
|
19
19
|
const permissions = userPermissionCache.get(user_id);
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const overrulingPermission = settings_1.authSettings.overrulingPermission();
|
|
21
|
+
if (overrulingPermission !== undefined) {
|
|
22
|
+
return permissions.includes(permission_id) || permissions.includes(overrulingPermission);
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
25
|
return permissions.includes(permission_id);
|
|
@@ -16,6 +16,7 @@ export interface IAuthPerformers {
|
|
|
16
16
|
export interface IAuthSettings {
|
|
17
17
|
allowSelfRegistration: boolean;
|
|
18
18
|
allowMultiLogin: boolean;
|
|
19
|
+
allowTestMode: boolean;
|
|
19
20
|
passwordHashLength: number;
|
|
20
21
|
passwordHashIterations: number;
|
|
21
22
|
firstAdmin: {
|
|
@@ -28,15 +29,18 @@ export interface IAuthSettings {
|
|
|
28
29
|
}
|
|
29
30
|
export declare namespace authSettings {
|
|
30
31
|
function init(settings: IAuthSettings, performers: IAuthPerformers): void;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
function allowSelfRegistration(): boolean;
|
|
33
|
+
function allowMultiLogin(): boolean;
|
|
34
|
+
function allowTestMode(): boolean;
|
|
35
|
+
function testMode(): boolean;
|
|
36
|
+
function changeTestMode(): boolean;
|
|
37
|
+
function passwordHashLength(): number;
|
|
38
|
+
function passwordHashIterations(): number;
|
|
39
|
+
function firstAdmin(): {
|
|
36
40
|
name: string;
|
|
37
41
|
email: string;
|
|
38
42
|
};
|
|
39
|
-
|
|
43
|
+
function overrulingPermission(): string | undefined;
|
|
40
44
|
function getPermissions(): Permission[];
|
|
41
45
|
function getRoles(): Role[];
|
|
42
46
|
function sendConfirmation(emailAddress: string, displayName: string, isInvited: boolean, confirmationLink: IAuthEmailLink): IResponsePromiseVoid;
|
package/dist/service/settings.js
CHANGED
|
@@ -4,9 +4,11 @@ exports.authSettings = void 0;
|
|
|
4
4
|
const core_1 = require("@hapiboo/core");
|
|
5
5
|
var authSettings;
|
|
6
6
|
(function (authSettings) {
|
|
7
|
+
let _test = false;
|
|
7
8
|
let _settings = {
|
|
8
9
|
allowSelfRegistration: true,
|
|
9
10
|
allowMultiLogin: false,
|
|
11
|
+
allowTestMode: false,
|
|
10
12
|
passwordHashLength: 1024,
|
|
11
13
|
passwordHashIterations: 32,
|
|
12
14
|
firstAdmin: {
|
|
@@ -17,33 +19,51 @@ var authSettings;
|
|
|
17
19
|
};
|
|
18
20
|
let _performers = undefined;
|
|
19
21
|
function init(settings, performers) {
|
|
20
|
-
console.
|
|
22
|
+
console.info('Authentication Settings Initialization');
|
|
21
23
|
_settings = settings;
|
|
22
24
|
_performers = performers;
|
|
23
25
|
}
|
|
24
26
|
authSettings.init = init;
|
|
25
|
-
|
|
27
|
+
function allowSelfRegistration() {
|
|
26
28
|
return _settings.allowSelfRegistration;
|
|
27
|
-
}
|
|
28
|
-
authSettings.
|
|
29
|
+
}
|
|
30
|
+
authSettings.allowSelfRegistration = allowSelfRegistration;
|
|
31
|
+
function allowMultiLogin() {
|
|
29
32
|
return _settings.allowMultiLogin;
|
|
30
|
-
}
|
|
31
|
-
authSettings.
|
|
33
|
+
}
|
|
34
|
+
authSettings.allowMultiLogin = allowMultiLogin;
|
|
35
|
+
function allowTestMode() {
|
|
36
|
+
return _settings.allowTestMode;
|
|
37
|
+
}
|
|
38
|
+
authSettings.allowTestMode = allowTestMode;
|
|
39
|
+
function testMode() {
|
|
40
|
+
return _test;
|
|
41
|
+
}
|
|
42
|
+
authSettings.testMode = testMode;
|
|
43
|
+
function changeTestMode() {
|
|
44
|
+
_test = !_test;
|
|
45
|
+
return _test;
|
|
46
|
+
}
|
|
47
|
+
authSettings.changeTestMode = changeTestMode;
|
|
48
|
+
function passwordHashLength() {
|
|
32
49
|
return _settings.passwordHashLength;
|
|
33
|
-
}
|
|
34
|
-
authSettings.
|
|
50
|
+
}
|
|
51
|
+
authSettings.passwordHashLength = passwordHashLength;
|
|
52
|
+
function passwordHashIterations() {
|
|
35
53
|
return _settings.passwordHashIterations;
|
|
36
|
-
}
|
|
37
|
-
authSettings.
|
|
38
|
-
|
|
54
|
+
}
|
|
55
|
+
authSettings.passwordHashIterations = passwordHashIterations;
|
|
56
|
+
function firstAdmin() {
|
|
39
57
|
return {
|
|
40
58
|
name: _settings.firstAdmin.name,
|
|
41
59
|
email: _settings.firstAdmin.email
|
|
42
60
|
};
|
|
43
|
-
}
|
|
44
|
-
authSettings.
|
|
61
|
+
}
|
|
62
|
+
authSettings.firstAdmin = firstAdmin;
|
|
63
|
+
function overrulingPermission() {
|
|
45
64
|
return _settings.overrulingPermission;
|
|
46
|
-
}
|
|
65
|
+
}
|
|
66
|
+
authSettings.overrulingPermission = overrulingPermission;
|
|
47
67
|
function getPermissions() {
|
|
48
68
|
if (_settings.getPermissions) {
|
|
49
69
|
return _settings.getPermissions();
|