@flink-app/generic-auth-plugin 0.12.1-alpha.27 → 0.12.1-alpha.28
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.ts +1 -1
- package/.flink/start.ts +1 -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/start.js +1 -1
- package/dist/src/handlers/UserLogin.js +39 -7
- package/package.json +2 -2
- package/src/handlers/UserLogin.ts +55 -31
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Mon Sep 22 2025 13:39:12 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 Mon Sep 22 2025 13:39:12 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 Mon Sep 22 2025 13:39:12 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredRepos } from "@flink-app/flink";
|
|
3
3
|
export const repos = [];
|
|
4
4
|
autoRegisteredRepos.push(...repos);
|
|
@@ -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 Mon Sep 22 2025 13:39:12 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,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 Mon Sep 22 2025 13:39:12 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 Mon Sep 22 2025 13:39:12 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 Mon Sep 22 2025 13:39:12 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);
|
package/dist/.flink/start.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated
|
|
3
|
+
// Generated Mon Sep 22 2025 13:39:12 GMT+0200 (Central European Summer Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
@@ -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)];
|
|
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.id,
|
|
68
|
+
title: error_1.title,
|
|
69
|
+
code: error_1.code,
|
|
70
|
+
detail: error_1.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": {} } };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/generic-auth-plugin",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.28",
|
|
4
4
|
"description": "Flink plugin that provides a generic user authentification solution.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ts-node": "^9.1.1",
|
|
31
31
|
"typescript": "5.4.5"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "cc427603defb6e3d3ea2e66f1bb23d19f11bd23c"
|
|
34
34
|
}
|
|
@@ -1,41 +1,65 @@
|
|
|
1
|
-
import { FlinkContext, Handler, unauthorized } from "@flink-app/flink";
|
|
1
|
+
import { FlinkContext, FlinkResponse, Handler, internalServerError, log, unauthorized } from "@flink-app/flink";
|
|
2
|
+
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
2
3
|
import { genericAuthContext } from "../genericAuthContext";
|
|
3
4
|
import { UserLoginReq } from "../schemas/UserLoginReq";
|
|
4
5
|
import { UserLoginRes } from "../schemas/UserLoginRes";
|
|
5
|
-
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
6
6
|
|
|
7
|
-
const userLoginHandler: Handler<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
(<any>ctx.plugins)[pluginName].onSuccessfulLogin
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (loginRespons.status != "success") {
|
|
26
|
-
switch (loginRespons.status) {
|
|
27
|
-
case "failed":
|
|
28
|
-
return unauthorized(
|
|
29
|
-
"Invalid username or password",
|
|
30
|
-
loginRespons.status
|
|
7
|
+
const userLoginHandler: Handler<FlinkContext<genericAuthContext>, UserLoginReq, UserLoginRes> = async ({ ctx, req, origin }) => {
|
|
8
|
+
let pluginName = origin || "genericAuthPlugin";
|
|
9
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
10
|
+
|
|
11
|
+
let loginResponse: UserLoginRes | undefined = undefined;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
loginResponse = await ctx.plugins.genericAuthPlugin.loginUser(
|
|
15
|
+
repo,
|
|
16
|
+
<JwtAuthPlugin>ctx.auth,
|
|
17
|
+
req.body.username,
|
|
18
|
+
req.body.password,
|
|
19
|
+
ctx.plugins.genericAuthPlugin.validatePasswordMethod,
|
|
20
|
+
(<any>ctx.plugins)[pluginName].smsOptions,
|
|
21
|
+
(<any>ctx.plugins)[pluginName].onSuccessfulLogin
|
|
31
22
|
);
|
|
23
|
+
} catch (error: any) {
|
|
24
|
+
// Convert any thrown error that conforms to flink error structure to a proper response
|
|
25
|
+
// Note that any auth failures would not have been thrown, but returned as part of loginResponse
|
|
26
|
+
// but with this it is possible to throw errors from callbacks like onSuccessfulLogin
|
|
27
|
+
if (isFlinkError(error)) {
|
|
28
|
+
log.debug("Caught FlinkError in userLoginHandler:", error);
|
|
29
|
+
return {
|
|
30
|
+
status: error.status,
|
|
31
|
+
error: {
|
|
32
|
+
id: error.id,
|
|
33
|
+
title: error.title,
|
|
34
|
+
code: error.code,
|
|
35
|
+
detail: error.detail,
|
|
36
|
+
},
|
|
37
|
+
} as FlinkResponse;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// For other errors, return a generic 500 response
|
|
41
|
+
log.error("Error in userLoginHandler:", error);
|
|
42
|
+
return internalServerError();
|
|
32
43
|
}
|
|
33
|
-
}
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
if (loginResponse?.status != "success") {
|
|
46
|
+
switch (loginResponse?.status) {
|
|
47
|
+
case "failed":
|
|
48
|
+
return unauthorized("Invalid username or password", loginResponse.status);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
data: loginResponse,
|
|
54
|
+
status: 200,
|
|
55
|
+
};
|
|
39
56
|
};
|
|
40
57
|
|
|
41
58
|
export default userLoginHandler;
|
|
59
|
+
|
|
60
|
+
function isFlinkError(res: any) {
|
|
61
|
+
if (res && res.status && typeof res.status === "number" && res.error && res.error.id) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|