@hapiboo/module-auth 1.1.3 → 1.2.1
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.
|
@@ -217,6 +217,7 @@ var authenticationService;
|
|
|
217
217
|
core_1.promise.checkVoid(authorization_1.authorizationService.general.initializeSecurityModel(), reject)
|
|
218
218
|
.then(() => {
|
|
219
219
|
//create first admin
|
|
220
|
+
console.info('creating first admin user: ' + settings_1.authSettings.firstAdmin.email);
|
|
220
221
|
core_1.promise.resolve(admin.invite(settings_1.authSettings.firstAdmin.email, settings_1.authSettings.firstAdmin.email, settings_1.authSettings.firstAdmin.name, baseURL), resolve, reject);
|
|
221
222
|
});
|
|
222
223
|
}
|
|
@@ -36,10 +36,10 @@ export declare namespace securityService {
|
|
|
36
36
|
function client(request: Request, response: Response, next: NextFunction): void;
|
|
37
37
|
function refresh(request: IFluxTokenRequest, response: Response, next: NextFunction): void;
|
|
38
38
|
function simple(request: IFluxRequest, response: Response, next: NextFunction): void;
|
|
39
|
+
function account(request: IFluxRequest, response: Response, next: NextFunction): void;
|
|
39
40
|
function full<TData>(request: IFluxDataRequest<TData>, response: Response, next: NextFunction): void;
|
|
40
|
-
function admin(request: IFluxRequest, response: Response, next: NextFunction): void;
|
|
41
|
-
function data<TData>(request: IFluxDataRequest<TData>, response: Response, next: NextFunction): void;
|
|
42
41
|
function checkAdmin(request: IFluxRequest, response: Response, next: NextFunction): void;
|
|
42
|
+
function checkAccount(request: IFluxRequest, response: Response, next: NextFunction): void;
|
|
43
43
|
function checkData<TData>(request: IFluxDataRequest<TData>, response: Response, next: NextFunction): void;
|
|
44
44
|
}
|
|
45
45
|
}
|
package/dist/service/security.js
CHANGED
|
@@ -141,6 +141,27 @@ var securityService;
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
middleware.simple = simple;
|
|
144
|
+
function account(request, response, next) {
|
|
145
|
+
request.payload = undefined;
|
|
146
|
+
try {
|
|
147
|
+
const payload = helpers.__validateTokenAndGetPayload(helpers.__retractRequestToken(request));
|
|
148
|
+
request.payload = { user_id: payload.user_id, account_id: payload.account_id, admin: payload.admin };
|
|
149
|
+
next();
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (error instanceof Error) {
|
|
153
|
+
response.status(401);
|
|
154
|
+
response.json({ error: error.message });
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
response.status(401);
|
|
159
|
+
response.json({ error: 'auth token validation error' });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
middleware.account = account;
|
|
144
165
|
function full(request, response, next) {
|
|
145
166
|
request.payload = undefined;
|
|
146
167
|
try {
|
|
@@ -162,7 +183,7 @@ var securityService;
|
|
|
162
183
|
}
|
|
163
184
|
}
|
|
164
185
|
middleware.full = full;
|
|
165
|
-
function
|
|
186
|
+
function _admin(request, response, next) {
|
|
166
187
|
if (request.payload && request.payload.admin) {
|
|
167
188
|
next();
|
|
168
189
|
}
|
|
@@ -171,8 +192,16 @@ var securityService;
|
|
|
171
192
|
response.json({ error: 'insufficient priviledges' });
|
|
172
193
|
}
|
|
173
194
|
}
|
|
174
|
-
|
|
175
|
-
|
|
195
|
+
function _account(request, response, next) {
|
|
196
|
+
if (request.payload && request.payload.account_id && request.payload.account_id != undefined) {
|
|
197
|
+
next();
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
response.status(400);
|
|
201
|
+
response.json({ error: 'malformed payload' });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function _data(request, response, next) {
|
|
176
205
|
if (request.payload && request.payload.data && request.payload.data != undefined) {
|
|
177
206
|
next();
|
|
178
207
|
}
|
|
@@ -181,16 +210,21 @@ var securityService;
|
|
|
181
210
|
response.json({ error: 'malformed payload data' });
|
|
182
211
|
}
|
|
183
212
|
}
|
|
184
|
-
middleware.data = data;
|
|
185
213
|
function checkAdmin(request, response, next) {
|
|
186
214
|
simple(request, response, () => {
|
|
187
|
-
|
|
215
|
+
_admin(request, response, next);
|
|
188
216
|
});
|
|
189
217
|
}
|
|
190
218
|
middleware.checkAdmin = checkAdmin;
|
|
219
|
+
function checkAccount(request, response, next) {
|
|
220
|
+
account(request, response, () => {
|
|
221
|
+
_account(request, response, next);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
middleware.checkAccount = checkAccount;
|
|
191
225
|
function checkData(request, response, next) {
|
|
192
226
|
full(request, response, () => {
|
|
193
|
-
|
|
227
|
+
_data(request, response, next);
|
|
194
228
|
});
|
|
195
229
|
}
|
|
196
230
|
middleware.checkData = checkData;
|
package/dist/service/settings.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hapiboo/module-auth",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "MK13 Studio Hapiboo - Auth Module",
|
|
5
5
|
"author": "MK13 Studio",
|
|
6
6
|
"license": "ISC",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@hapiboo/core": "^3.0.6",
|
|
17
17
|
"@hapiboo/crypto": "^3.0.1",
|
|
18
|
-
"@hapiboo/date": "^3.0.
|
|
18
|
+
"@hapiboo/date": "^3.0.4",
|
|
19
19
|
"@hapiboo/flux": "^1.1.4",
|
|
20
20
|
"@hapiboo/server": "^3.0.2",
|
|
21
21
|
"express": "^5.2.1",
|