@flink-app/generic-auth-plugin 0.12.1-alpha.3 → 0.12.1-alpha.33
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/.flink/generatedHandlers.ts +1 -1
- package/.flink/generatedJobs.ts +1 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.json +7 -2
- package/.flink/schemas/schemas.ts +1 -1
- package/.flink/start.ts +2 -1
- package/dist/.flink/generatedHandlers.js +1 -1
- package/dist/.flink/generatedJobs.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/schemas/schemas.json +7 -2
- package/dist/.flink/start.d.ts +2 -0
- package/dist/.flink/start.js +2 -1
- package/dist/src/coreFunctions.d.ts +5 -5
- package/dist/src/coreFunctions.js +22 -4
- package/dist/src/genericAuthContext.d.ts +5 -5
- package/dist/src/genericAuthPluginOptions.d.ts +2 -1
- package/dist/src/handlers/UserCreate.js +4 -4
- package/dist/src/handlers/UserLogin.js +39 -7
- package/dist/src/handlers/UserPasswordResetComplete.js +1 -1
- package/dist/src/handlers/UserPushRegisterToken.js +1 -1
- package/dist/src/schemas/User.d.ts +2 -1
- package/dist/src/schemas/UserCreateReq.d.ts +2 -1
- package/dist/src/schemas/UserPasswordResetCompleteRes.d.ts +4 -0
- package/package.json +8 -8
- package/readme.md +627 -565
- package/src/coreFunctions.ts +29 -7
- package/src/genericAuthContext.ts +7 -5
- package/src/genericAuthPluginOptions.ts +2 -1
- package/src/handlers/UserCreate.ts +3 -2
- package/src/handlers/UserLogin.ts +56 -31
- package/src/handlers/UserPushRegisterToken.ts +1 -1
- package/src/schemas/User.ts +2 -1
- package/src/schemas/UserCreateReq.ts +5 -4
- package/src/schemas/UserPasswordResetCompleteRes.ts +8 -3
- package/CLAUDE.md +0 -32
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
|
|
3
3
|
import * as UserCreate_0 from "../src/handlers/UserCreate";
|
|
4
4
|
import * as UserLogin_0 from "../src/handlers/UserLogin";
|
package/.flink/generatedJobs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredJobs } from "@flink-app/flink";
|
|
3
3
|
export const jobs = [];
|
|
4
4
|
autoRegisteredJobs.push(...jobs);
|
package/.flink/generatedRepos.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredRepos } from "@flink-app/flink";
|
|
3
3
|
export const repos = [];
|
|
4
4
|
autoRegisteredRepos.push(...repos);
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
"password": {
|
|
14
14
|
"type": "string"
|
|
15
15
|
},
|
|
16
|
+
"personalNumber": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
16
19
|
"authentificationMethod": {
|
|
17
20
|
"type": "string",
|
|
18
21
|
"enum": [
|
|
19
22
|
"password",
|
|
20
|
-
"sms"
|
|
23
|
+
"sms",
|
|
24
|
+
"bankid"
|
|
21
25
|
]
|
|
22
26
|
},
|
|
23
27
|
"profile": {
|
|
@@ -264,7 +268,8 @@
|
|
|
264
268
|
"invalidCode",
|
|
265
269
|
"passwordError"
|
|
266
270
|
]
|
|
267
|
-
}
|
|
271
|
+
},
|
|
272
|
+
"user": {}
|
|
268
273
|
},
|
|
269
274
|
"required": [
|
|
270
275
|
"status"
|
|
@@ -29,7 +29,7 @@ import { PutManagementUserRolesByUseridRes } from "../../src/schemas/Management/
|
|
|
29
29
|
import { PutManagementUserUsernameByUseridReq } from "../../src/schemas/Management/PutUserUsernameByUseridReq";
|
|
30
30
|
import { PutManagementUserUsernameByUseridRes } from "../../src/schemas/Management/PutUserUsernameByUseridRes";
|
|
31
31
|
|
|
32
|
-
// Generated
|
|
32
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
33
33
|
export interface UserCreate_7_ReqSchema extends UserCreateReq {}
|
|
34
34
|
|
|
35
35
|
export interface UserCreate_7_ResSchema extends UserCreateRes {}
|
package/.flink/start.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import "./generatedHandlers";
|
|
3
3
|
import "./generatedRepos";
|
|
4
4
|
import "./generatedJobs";
|
|
5
5
|
import "../src/index";
|
|
6
|
+
export default {}; // Export an empty object to make it a module
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlers = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.handlers = [];
|
|
7
7
|
flink_1.autoRegisteredHandlers.push.apply(flink_1.autoRegisteredHandlers, exports.handlers);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jobs = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.jobs = [];
|
|
7
7
|
flink_1.autoRegisteredJobs.push.apply(flink_1.autoRegisteredJobs, exports.jobs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.repos = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.repos = [];
|
|
7
7
|
flink_1.autoRegisteredRepos.push.apply(flink_1.autoRegisteredRepos, exports.repos);
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
"password": {
|
|
14
14
|
"type": "string"
|
|
15
15
|
},
|
|
16
|
+
"personalNumber": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
16
19
|
"authentificationMethod": {
|
|
17
20
|
"type": "string",
|
|
18
21
|
"enum": [
|
|
19
22
|
"password",
|
|
20
|
-
"sms"
|
|
23
|
+
"sms",
|
|
24
|
+
"bankid"
|
|
21
25
|
]
|
|
22
26
|
},
|
|
23
27
|
"profile": {
|
|
@@ -264,7 +268,8 @@
|
|
|
264
268
|
"invalidCode",
|
|
265
269
|
"passwordError"
|
|
266
270
|
]
|
|
267
|
-
}
|
|
271
|
+
},
|
|
272
|
+
"user": {}
|
|
268
273
|
},
|
|
269
274
|
"required": [
|
|
270
275
|
"status"
|
package/dist/.flink/start.d.ts
CHANGED
package/dist/.flink/start.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated
|
|
3
|
+
// Generated Fri Oct 24 2025 08:14:04 GMT+0200 (Central European Summer Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
7
7
|
require("../src/index");
|
|
8
|
+
exports.default = {}; // Export an empty object to make it a module
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkRepo } from "@flink-app/flink";
|
|
1
|
+
import { FlinkRepo, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
3
3
|
import { User } from "./schemas/User";
|
|
4
4
|
import { UserCreateRes } from "./schemas/UserCreateRes";
|
|
@@ -11,20 +11,20 @@ import { GenericAuthsmsOptions } from "./genericAuthPluginOptions";
|
|
|
11
11
|
export declare function getJtwTokenPlugin(secret: string, rolePermissions?: {
|
|
12
12
|
[role: string]: string[];
|
|
13
13
|
}, passwordPolicy?: RegExp, tokenTTL?: number): JwtAuthPlugin;
|
|
14
|
-
export declare function createUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string, authentificationMethod: "password" | "sms", roles: string[], profile: UserProfile, createPasswordHashAndSaltMethod?: {
|
|
14
|
+
export declare function createUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string, authentificationMethod: "password" | "sms" | "bankid", roles: string[], profile: UserProfile, createPasswordHashAndSaltMethod?: {
|
|
15
15
|
(password: string): Promise<{
|
|
16
16
|
hash: string;
|
|
17
17
|
salt: string;
|
|
18
18
|
} | null>;
|
|
19
19
|
}, onUserCreated?: {
|
|
20
20
|
(user: User): Promise<void>;
|
|
21
|
-
}): Promise<UserCreateRes>;
|
|
21
|
+
}, personalNumber?: string): Promise<UserCreateRes>;
|
|
22
22
|
export declare function loginByToken(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, token: string, code: string, jwtSecret: string): Promise<UserLoginRes>;
|
|
23
23
|
export declare function loginUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string | undefined, validatePasswordMethod?: {
|
|
24
24
|
(password: string, hash: string, salt: string): Promise<boolean>;
|
|
25
25
|
}, smsOptions?: GenericAuthsmsOptions, onSuccessfulLogin?: {
|
|
26
|
-
(user: User): Promise<void>;
|
|
27
|
-
}): Promise<UserLoginRes>;
|
|
26
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
27
|
+
}, req?: FlinkRequest): Promise<UserLoginRes>;
|
|
28
28
|
export declare function changePassword(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, userId: string, newPassword: string, createPasswordHashAndSaltMethod?: {
|
|
29
29
|
(password: string): Promise<{
|
|
30
30
|
hash: string;
|
|
@@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.passwordResetComplete = exports.passwordResetStart = exports.changePassword = exports.loginUser = exports.loginByToken = exports.createUser = exports.getJtwTokenPlugin = void 0;
|
|
43
|
+
var flink_1 = require("@flink-app/flink");
|
|
43
44
|
var jwt_auth_plugin_1 = require("@flink-app/jwt-auth-plugin");
|
|
44
45
|
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
45
46
|
function getJtwTokenPlugin(secret, rolePermissions, passwordPolicy, tokenTTL) {
|
|
@@ -70,7 +71,7 @@ function getJtwTokenPlugin(secret, rolePermissions, passwordPolicy, tokenTTL) {
|
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
73
|
exports.getJtwTokenPlugin = getJtwTokenPlugin;
|
|
73
|
-
function createUser(repo, auth, username, password, authentificationMethod, roles, profile, createPasswordHashAndSaltMethod, onUserCreated) {
|
|
74
|
+
function createUser(repo, auth, username, password, authentificationMethod, roles, profile, createPasswordHashAndSaltMethod, onUserCreated, personalNumber) {
|
|
74
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
75
76
|
var existingUser, userData, passwordAndSalt, user, token;
|
|
76
77
|
return __generator(this, function (_a) {
|
|
@@ -93,6 +94,15 @@ function createUser(repo, auth, username, password, authentificationMethod, role
|
|
|
93
94
|
authentificationMethod: authentificationMethod,
|
|
94
95
|
pushNotificationTokens: [],
|
|
95
96
|
};
|
|
97
|
+
if (personalNumber) {
|
|
98
|
+
userData.personalNumber = personalNumber;
|
|
99
|
+
}
|
|
100
|
+
if (authentificationMethod == "bankid") {
|
|
101
|
+
if (!personalNumber) {
|
|
102
|
+
flink_1.log.warn("BankID login requested but no personal number found for user");
|
|
103
|
+
return [2 /*return*/, { status: "error" }];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
96
106
|
if (!(authentificationMethod == "password")) return [3 /*break*/, 6];
|
|
97
107
|
passwordAndSalt = null;
|
|
98
108
|
if (!(createPasswordHashAndSaltMethod != null)) return [3 /*break*/, 3];
|
|
@@ -180,7 +190,7 @@ function loginByToken(repo, auth, token, code, jwtSecret) {
|
|
|
180
190
|
});
|
|
181
191
|
}
|
|
182
192
|
exports.loginByToken = loginByToken;
|
|
183
|
-
function loginUser(repo, auth, username, password, validatePasswordMethod, smsOptions, onSuccessfulLogin) {
|
|
193
|
+
function loginUser(repo, auth, username, password, validatePasswordMethod, smsOptions, onSuccessfulLogin, req) {
|
|
184
194
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
195
|
var user, valid, ex_1, code, payload, secret, options, token, token;
|
|
186
196
|
return __generator(this, function (_a) {
|
|
@@ -239,12 +249,20 @@ function loginUser(repo, auth, username, password, validatePasswordMethod, smsOp
|
|
|
239
249
|
validationToken: token,
|
|
240
250
|
}];
|
|
241
251
|
}
|
|
252
|
+
if (user.authentificationMethod == "bankid") {
|
|
253
|
+
if (!user.personalNumber) {
|
|
254
|
+
flink_1.log.warn("BankID login requested but no personal number found for user");
|
|
255
|
+
return [2 /*return*/, { status: "failed" }];
|
|
256
|
+
}
|
|
257
|
+
flink_1.log.warn("BankID login required to be handled in other way, i.e. using flink bankid plugin");
|
|
258
|
+
return [2 /*return*/, { status: "failed" }];
|
|
259
|
+
}
|
|
242
260
|
if (!valid) return [3 /*break*/, 13];
|
|
243
261
|
return [4 /*yield*/, auth.createToken({ username: username.toLowerCase(), _id: user._id }, user.roles)];
|
|
244
262
|
case 10:
|
|
245
263
|
token = _a.sent();
|
|
246
264
|
if (!onSuccessfulLogin) return [3 /*break*/, 12];
|
|
247
|
-
return [4 /*yield*/, onSuccessfulLogin(user)];
|
|
265
|
+
return [4 /*yield*/, onSuccessfulLogin(user, req)];
|
|
248
266
|
case 11:
|
|
249
267
|
_a.sent();
|
|
250
268
|
_a.label = 12;
|
|
@@ -414,7 +432,7 @@ function passwordResetComplete(repo_1, auth_1, jwtSecret_1, passwordResetToken_1
|
|
|
414
432
|
})];
|
|
415
433
|
case 6:
|
|
416
434
|
_a.sent();
|
|
417
|
-
return [2 /*return*/, { status: "success" }];
|
|
435
|
+
return [2 /*return*/, { status: "success", user: user }];
|
|
418
436
|
}
|
|
419
437
|
});
|
|
420
438
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkRepo } from "@flink-app/flink";
|
|
1
|
+
import { FlinkRepo, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
3
3
|
import { User } from "./schemas/User";
|
|
4
4
|
import { UserCreateRes } from "./schemas/UserCreateRes";
|
|
@@ -13,14 +13,14 @@ export interface genericAuthContext {
|
|
|
13
13
|
genericAuthPlugin: {
|
|
14
14
|
loginUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password?: string, validatePasswordMethod?: {
|
|
15
15
|
(password: string, hash: string, salt: string): Promise<boolean>;
|
|
16
|
-
}, smsOptions?: GenericAuthsmsOptions, onSuccessfulLogin?: (user: User) => Promise<void
|
|
16
|
+
}, smsOptions?: GenericAuthsmsOptions, onSuccessfulLogin?: (user: User, req?: FlinkRequest) => Promise<void>, req?: FlinkRequest): Promise<UserLoginRes>;
|
|
17
17
|
loginByToken(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, token: string, code: string, jwtSecret: string): Promise<UserLoginRes>;
|
|
18
|
-
createUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string, authentificationMethod: "password" | "sms", roles: string[], profile: UserProfile, createPasswordHashAndSaltMethod?: {
|
|
18
|
+
createUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string, authentificationMethod: "password" | "sms" | "bankid", roles: string[], profile: UserProfile, createPasswordHashAndSaltMethod?: {
|
|
19
19
|
(password: string): Promise<{
|
|
20
20
|
hash: string;
|
|
21
21
|
salt: string;
|
|
22
22
|
} | null>;
|
|
23
|
-
}, onUserCreated?: (user: User) => Promise<void
|
|
23
|
+
}, onUserCreated?: (user: User) => Promise<void>, personalNumber?: string): Promise<UserCreateRes>;
|
|
24
24
|
changePassword(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, userId: string, newPassword: string, createPasswordHashAndSaltMethod?: {
|
|
25
25
|
(password: string): Promise<{
|
|
26
26
|
hash: string;
|
|
@@ -48,7 +48,7 @@ export interface genericAuthContext {
|
|
|
48
48
|
usernameFormat: RegExp;
|
|
49
49
|
smsOptions?: GenericAuthsmsOptions;
|
|
50
50
|
onSuccessfulLogin?: {
|
|
51
|
-
(user: User): Promise<void>;
|
|
51
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
52
52
|
};
|
|
53
53
|
onUserCreated?: {
|
|
54
54
|
(user: User): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FlinkRequest } from "@flink-app/flink";
|
|
1
2
|
import { User } from "./schemas/User";
|
|
2
3
|
import { UserPasswordResetSettings } from "./schemas/UserPasswordResetSettings";
|
|
3
4
|
import { client as smsClient } from "@flink-app/sms-plugin";
|
|
@@ -26,7 +27,7 @@ export interface GenericAuthPluginOptions {
|
|
|
26
27
|
usernameFormat?: RegExp;
|
|
27
28
|
sms?: GenericAuthsmsOptions;
|
|
28
29
|
onSuccessfulLogin?: {
|
|
29
|
-
(user: User): Promise<void>;
|
|
30
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
30
31
|
};
|
|
31
32
|
onUserCreated?: {
|
|
32
33
|
(user: User): Promise<void>;
|
|
@@ -39,12 +39,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
40
40
|
var flink_1 = require("@flink-app/flink");
|
|
41
41
|
var userCreateHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
42
|
-
var _c, password, username, authentificationMethod, profile, roles, pluginName, repo, re, createUserResponse;
|
|
42
|
+
var _c, password, username, authentificationMethod, profile, personalNumber, roles, pluginName, repo, re, createUserResponse;
|
|
43
43
|
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
44
44
|
return __generator(this, function (_d) {
|
|
45
45
|
switch (_d.label) {
|
|
46
46
|
case 0:
|
|
47
|
-
_c = req.body, password = _c.password, username = _c.username, authentificationMethod = _c.authentificationMethod, profile = _c.profile;
|
|
47
|
+
_c = req.body, password = _c.password, username = _c.username, authentificationMethod = _c.authentificationMethod, profile = _c.profile, personalNumber = _c.personalNumber;
|
|
48
48
|
if (authentificationMethod == null) {
|
|
49
49
|
authentificationMethod = "password";
|
|
50
50
|
}
|
|
@@ -63,7 +63,7 @@ var userCreateHandler = function (_a) { return __awaiter(void 0, [_a], void 0, f
|
|
|
63
63
|
if (!re.test(username)) {
|
|
64
64
|
return [2 /*return*/, (0, flink_1.badRequest)("Username does not meet requirements", "usernameError")];
|
|
65
65
|
}
|
|
66
|
-
return [4 /*yield*/, ctx.plugins.genericAuthPlugin.createUser(repo, ctx.auth, username.toLocaleLowerCase(), password, authentificationMethod, roles, profile, ctx.plugins[pluginName].createPasswordHashAndSaltMethod, ctx.plugins[pluginName].onUserCreated)];
|
|
66
|
+
return [4 /*yield*/, ctx.plugins.genericAuthPlugin.createUser(repo, ctx.auth, username.toLocaleLowerCase(), password, authentificationMethod, roles, profile, ctx.plugins[pluginName].createPasswordHashAndSaltMethod, ctx.plugins[pluginName].onUserCreated, personalNumber)];
|
|
67
67
|
case 1:
|
|
68
68
|
createUserResponse = _d.sent();
|
|
69
69
|
if (createUserResponse.status != "success") {
|
|
@@ -85,4 +85,4 @@ var userCreateHandler = function (_a) { return __awaiter(void 0, [_a], void 0, f
|
|
|
85
85
|
}); };
|
|
86
86
|
exports.default = userCreateHandler;
|
|
87
87
|
exports.__assumedHttpMethod = "", exports.__file = "UserCreate.ts", exports.__query = [], exports.__params = [];
|
|
88
|
-
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "password": { "type": "string" }, "authentificationMethod": { "type": "string", "enum": ["password", "sms"] }, "profile": { "type": "object" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "error", "userExists", "passwordError"] }, "user": { "type": "object", "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "token": { "type": "string" } }, "required": ["_id", "username", "token"], "additionalProperties": false } }, "required": ["status"], "definitions": {} } };
|
|
88
|
+
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "password": { "type": "string" }, "personalNumber": { "type": "string" }, "authentificationMethod": { "type": "string", "enum": ["password", "sms", "bankid"] }, "profile": { "type": "object" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "error", "userExists", "passwordError"] }, "user": { "type": "object", "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "token": { "type": "string" } }, "required": ["_id", "username", "token"], "additionalProperties": false } }, "required": ["status"], "definitions": {} } };
|
|
@@ -39,29 +39,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
40
40
|
var flink_1 = require("@flink-app/flink");
|
|
41
41
|
var userLoginHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
42
|
-
var pluginName, repo,
|
|
42
|
+
var pluginName, repo, loginResponse, error_1;
|
|
43
43
|
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
44
44
|
return __generator(this, function (_c) {
|
|
45
45
|
switch (_c.label) {
|
|
46
46
|
case 0:
|
|
47
47
|
pluginName = origin || "genericAuthPlugin";
|
|
48
48
|
repo = ctx.repos[ctx.plugins[pluginName].repoName];
|
|
49
|
-
|
|
49
|
+
loginResponse = undefined;
|
|
50
|
+
_c.label = 1;
|
|
50
51
|
case 1:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
_c.trys.push([1, 3, , 4]);
|
|
53
|
+
return [4 /*yield*/, ctx.plugins.genericAuthPlugin.loginUser(repo, ctx.auth, req.body.username, req.body.password, ctx.plugins.genericAuthPlugin.validatePasswordMethod, ctx.plugins[pluginName].smsOptions, ctx.plugins[pluginName].onSuccessfulLogin, req)];
|
|
54
|
+
case 2:
|
|
55
|
+
loginResponse = _c.sent();
|
|
56
|
+
return [3 /*break*/, 4];
|
|
57
|
+
case 3:
|
|
58
|
+
error_1 = _c.sent();
|
|
59
|
+
// Convert any thrown error that conforms to flink error structure to a proper response
|
|
60
|
+
// Note that any auth failures would not have been thrown, but returned as part of loginResponse
|
|
61
|
+
// but with this it is possible to throw errors from callbacks like onSuccessfulLogin
|
|
62
|
+
if (isFlinkError(error_1)) {
|
|
63
|
+
flink_1.log.debug("Caught FlinkError in userLoginHandler:", error_1);
|
|
64
|
+
return [2 /*return*/, {
|
|
65
|
+
status: error_1.status,
|
|
66
|
+
error: {
|
|
67
|
+
id: error_1.error.id,
|
|
68
|
+
title: error_1.error.title,
|
|
69
|
+
code: error_1.error.code,
|
|
70
|
+
detail: error_1.error.detail,
|
|
71
|
+
},
|
|
72
|
+
}];
|
|
73
|
+
}
|
|
74
|
+
// For other errors, return a generic 500 response
|
|
75
|
+
flink_1.log.error("Error in userLoginHandler:", error_1);
|
|
76
|
+
return [2 /*return*/, (0, flink_1.internalServerError)()];
|
|
77
|
+
case 4:
|
|
78
|
+
if ((loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.status) != "success") {
|
|
79
|
+
switch (loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.status) {
|
|
54
80
|
case "failed":
|
|
55
|
-
return [2 /*return*/, (0, flink_1.unauthorized)("Invalid username or password",
|
|
81
|
+
return [2 /*return*/, (0, flink_1.unauthorized)("Invalid username or password", loginResponse.status)];
|
|
56
82
|
}
|
|
57
83
|
}
|
|
58
84
|
return [2 /*return*/, {
|
|
59
|
-
data:
|
|
85
|
+
data: loginResponse,
|
|
60
86
|
status: 200,
|
|
61
87
|
}];
|
|
62
88
|
}
|
|
63
89
|
});
|
|
64
90
|
}); };
|
|
65
91
|
exports.default = userLoginHandler;
|
|
92
|
+
function isFlinkError(res) {
|
|
93
|
+
if (res && res.status && typeof res.status === "number" && res.error && res.error.id) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
66
98
|
exports.__assumedHttpMethod = "", exports.__file = "UserLogin.ts", exports.__query = [], exports.__params = [];
|
|
67
99
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "password": { "type": "string" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "failed", "requiresValidation"] }, "user": { "type": "object", "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "token": { "type": "string" }, "profile": { "type": "object" } }, "required": ["_id", "username", "token", "profile"], "additionalProperties": false }, "validationToken": { "type": "string" } }, "required": ["status"], "definitions": {} } };
|
|
@@ -67,4 +67,4 @@ var postPasswordResetCompleteHandler = function (_a) { return __awaiter(void 0,
|
|
|
67
67
|
}); };
|
|
68
68
|
exports.default = postPasswordResetCompleteHandler;
|
|
69
69
|
exports.__assumedHttpMethod = "", exports.__file = "UserPasswordResetComplete.ts", exports.__query = [], exports.__params = [];
|
|
70
|
-
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "passwordResetToken": { "type": "string" }, "code": { "type": "string" }, "password": { "type": "string" } }, "required": ["code", "password", "passwordResetToken"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "userNotFound", "invalidCode", "passwordError"] } }, "required": ["status"], "definitions": {} } };
|
|
70
|
+
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "passwordResetToken": { "type": "string" }, "code": { "type": "string" }, "password": { "type": "string" } }, "required": ["code", "password", "passwordResetToken"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "userNotFound", "invalidCode", "passwordError"] }, "user": {} }, "required": ["status"], "definitions": {} } };
|
|
@@ -87,7 +87,7 @@ var postUserPushRegisterTokenHandler = function (_a) { return __awaiter(void 0,
|
|
|
87
87
|
if (!deregisterOtherDevices) return [3 /*break*/, 9];
|
|
88
88
|
return [4 /*yield*/, repo.findAll({
|
|
89
89
|
$or: [{ "pushNotificationTokens.deviceId": req.body.deviceId }, { "pushNotificationTokens.token": req.body.token }],
|
|
90
|
-
_id: { $ne: user._id },
|
|
90
|
+
_id: { $ne: repo.buildId(user._id) },
|
|
91
91
|
})];
|
|
92
92
|
case 3:
|
|
93
93
|
otherRegistrations = _d.sent();
|
|
@@ -3,11 +3,12 @@ import { UserProfile } from "./UserProfile";
|
|
|
3
3
|
export interface User {
|
|
4
4
|
_id: string;
|
|
5
5
|
username: string;
|
|
6
|
+
personalNumber?: string;
|
|
6
7
|
password?: string;
|
|
7
8
|
salt?: string;
|
|
8
9
|
pwdResetStartedAt?: string | null;
|
|
9
10
|
roles: string[];
|
|
10
|
-
authentificationMethod: "password" | "sms";
|
|
11
|
+
authentificationMethod: "password" | "sms" | "bankid";
|
|
11
12
|
profile: UserProfile;
|
|
12
13
|
pushNotificationTokens: Array<PushNotificationToken>;
|
|
13
14
|
}
|
|
@@ -2,6 +2,7 @@ import { UserProfile } from "./UserProfile";
|
|
|
2
2
|
export interface UserCreateReq {
|
|
3
3
|
username: string;
|
|
4
4
|
password?: string;
|
|
5
|
-
|
|
5
|
+
personalNumber?: string;
|
|
6
|
+
authentificationMethod?: "password" | "sms" | "bankid";
|
|
6
7
|
profile?: UserProfile;
|
|
7
8
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/generic-auth-plugin",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.33",
|
|
4
4
|
"description": "Flink plugin that provides a generic user authentification solution.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
7
7
|
"build": "flink build",
|
|
8
|
-
"
|
|
8
|
+
"prepare": "npm run build",
|
|
9
9
|
"watch": "nodemon --exec \"flink build\""
|
|
10
10
|
},
|
|
11
11
|
"author": "johan@frost.se",
|
|
@@ -16,19 +16,19 @@
|
|
|
16
16
|
"types": "dist/src/index.d.ts",
|
|
17
17
|
"main": "dist/src/index.js",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@flink-app/email-plugin": "^0.12.1-alpha.
|
|
20
|
-
"@flink-app/jwt-auth-plugin": "^0.12.1-alpha.
|
|
21
|
-
"@flink-app/management-api-plugin": "^0.12.1-alpha.
|
|
22
|
-
"@flink-app/sms-plugin": "^0.12.1-alpha.
|
|
19
|
+
"@flink-app/email-plugin": "^0.12.1-alpha.33",
|
|
20
|
+
"@flink-app/jwt-auth-plugin": "^0.12.1-alpha.33",
|
|
21
|
+
"@flink-app/management-api-plugin": "^0.12.1-alpha.33",
|
|
22
|
+
"@flink-app/sms-plugin": "^0.12.1-alpha.33",
|
|
23
23
|
"handlebars": "^4.7.7",
|
|
24
24
|
"jsonwebtoken": "^8.5.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@flink-app/flink": "^0.12.1-alpha.
|
|
27
|
+
"@flink-app/flink": "^0.12.1-alpha.23",
|
|
28
28
|
"@types/jsonwebtoken": "^8.5.2",
|
|
29
29
|
"@types/node": "22.13.10",
|
|
30
30
|
"ts-node": "^9.1.1",
|
|
31
31
|
"typescript": "5.4.5"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "eec3a22c21db0e7fec84190bf7a74c1e430e5ec4"
|
|
34
34
|
}
|