@flink-app/generic-auth-plugin 0.6.2 → 0.6.5
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/coreFunctions.js +8 -3
- package/dist/src/handlers/UserPasswordResetStart.js +11 -7
- package/dist/src/schemas/UserPasswordResetSettings.d.ts +14 -5
- package/package.json +3 -3
- package/src/coreFunctions.ts +11 -2
- package/src/handlers/UserPasswordResetStart.ts +41 -49
- package/src/schemas/UserPasswordResetSettings.ts +21 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Mon Nov 06 2023 09:51:29 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:29 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:29 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:31 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:29 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:29 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:29 GMT+0100 (Central European Standard 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 Nov 06 2023 09:51:29 GMT+0100 (Central European Standard Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
@@ -297,17 +297,22 @@ function changePassword(repo, auth, userId, newPassword, createPasswordHashAndSa
|
|
|
297
297
|
exports.changePassword = changePassword;
|
|
298
298
|
function passwordResetStart(repo, auth, jwtSecret, username, numberOfDigits, lifeTime) {
|
|
299
299
|
return __awaiter(this, void 0, void 0, function () {
|
|
300
|
-
var user, payload, code, secret, options, token;
|
|
300
|
+
var user, fakepayload, fakeToken, payload, code, secret, options, token;
|
|
301
301
|
return __generator(this, function (_a) {
|
|
302
302
|
switch (_a.label) {
|
|
303
303
|
case 0: return [4 /*yield*/, repo.getOne({ username: username.toLowerCase() })];
|
|
304
304
|
case 1:
|
|
305
305
|
user = _a.sent();
|
|
306
|
+
fakepayload = {
|
|
307
|
+
type: "passwordReset",
|
|
308
|
+
username: username.toLocaleLowerCase(),
|
|
309
|
+
};
|
|
310
|
+
fakeToken = jsonwebtoken_1.default.sign(fakepayload, "fake_payload", { expiresIn: lifeTime });
|
|
306
311
|
if (user == null) {
|
|
307
|
-
return [2 /*return*/, { status: "userNotFound" }];
|
|
312
|
+
return [2 /*return*/, { status: "userNotFound", passwordResetToken: fakeToken }];
|
|
308
313
|
}
|
|
309
314
|
if (user.authentificationMethod != "password") {
|
|
310
|
-
return [2 /*return*/, { status: "userNotFound" }];
|
|
315
|
+
return [2 /*return*/, { status: "userNotFound", passwordResetToken: fakeToken }];
|
|
311
316
|
}
|
|
312
317
|
if (numberOfDigits == null)
|
|
313
318
|
numberOfDigits = 6;
|
|
@@ -45,33 +45,37 @@ var handlebars_1 = __importDefault(require("handlebars"));
|
|
|
45
45
|
var postPasswordResetStartHandler = function (_a) {
|
|
46
46
|
var ctx = _a.ctx, req = _a.req, origin = _a.origin;
|
|
47
47
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
-
var pluginName, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp,
|
|
48
|
+
var pluginName, genericAuthPlugin, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp, emailCtx, emailSettings, subject, html, email;
|
|
49
49
|
var _c;
|
|
50
50
|
return __generator(this, function (_d) {
|
|
51
51
|
switch (_d.label) {
|
|
52
52
|
case 0:
|
|
53
53
|
pluginName = origin || "genericAuthPlugin";
|
|
54
|
-
|
|
54
|
+
genericAuthPlugin = ctx.plugins[pluginName];
|
|
55
|
+
repo = ctx.repos[genericAuthPlugin.repoName];
|
|
55
56
|
if (((_c = ctx.plugins.emailPlugin) === null || _c === void 0 ? void 0 : _c.client) == null) {
|
|
56
57
|
return [2 /*return*/, flink_1.internalServerError("Email plugin have to be initialized to use /password/reset")];
|
|
57
58
|
}
|
|
58
|
-
if (
|
|
59
|
+
if (!genericAuthPlugin.passwordResetSettings) {
|
|
59
60
|
return [2 /*return*/, flink_1.internalServerError("Password reset settings is needed to use /password/reset")];
|
|
60
61
|
}
|
|
61
|
-
_b =
|
|
62
|
-
return [4 /*yield*/,
|
|
62
|
+
_b = genericAuthPlugin.passwordResetSettings.code, jwtSecret = _b.jwtSecret, numberOfDigits = _b.numberOfDigits, lifeTime = _b.lifeTime;
|
|
63
|
+
return [4 /*yield*/, genericAuthPlugin.passwordResetStart(repo, ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime)];
|
|
63
64
|
case 1:
|
|
64
65
|
resp = _d.sent();
|
|
65
66
|
if (resp.status != "success") {
|
|
66
|
-
return [2 /*return*/, { data: { status: resp.
|
|
67
|
+
return [2 /*return*/, { data: { status: "success", passwordResetToken: resp.passwordResetToken } }];
|
|
67
68
|
}
|
|
68
|
-
emailSettings = ctx.plugins[pluginName].passwordResetSettings.email;
|
|
69
69
|
emailCtx = {
|
|
70
70
|
code: resp.code,
|
|
71
71
|
passwordResetToken: resp.passwordResetToken,
|
|
72
72
|
username: req.body.username,
|
|
73
73
|
profile: resp.profile,
|
|
74
74
|
};
|
|
75
|
+
emailSettings = genericAuthPlugin.passwordResetSettings.email;
|
|
76
|
+
if (typeof emailSettings == "function") {
|
|
77
|
+
emailSettings = emailSettings(emailCtx);
|
|
78
|
+
}
|
|
75
79
|
subject = handlebars_1.default.compile(emailSettings.subject)(emailCtx);
|
|
76
80
|
html = handlebars_1.default.compile(emailSettings.html)(emailCtx);
|
|
77
81
|
email = req.body.username;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { UserProfile } from "./UserProfile";
|
|
2
|
+
interface EmailConfig {
|
|
3
|
+
from_address: string;
|
|
4
|
+
subject: string;
|
|
5
|
+
html: string;
|
|
6
|
+
}
|
|
7
|
+
interface EmailCtx {
|
|
8
|
+
code?: string;
|
|
9
|
+
passwordResetToken?: string;
|
|
10
|
+
username: string;
|
|
11
|
+
profile?: UserProfile;
|
|
12
|
+
}
|
|
1
13
|
export interface UserPasswordResetSettings {
|
|
2
|
-
email:
|
|
3
|
-
from_address: string;
|
|
4
|
-
subject: string;
|
|
5
|
-
html: string;
|
|
6
|
-
};
|
|
14
|
+
email: EmailConfig | ((emailCtx: EmailCtx) => EmailConfig);
|
|
7
15
|
code: {
|
|
8
16
|
numberOfDigits: number;
|
|
9
17
|
lifeTime: string;
|
|
@@ -12,3 +20,4 @@ export interface UserPasswordResetSettings {
|
|
|
12
20
|
enablePasswordResetForm?: boolean;
|
|
13
21
|
passwordResetForm?: string;
|
|
14
22
|
}
|
|
23
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/generic-auth-plugin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Flink plugin that provides a generic user authentification solution.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"types": "dist/src/index.d.ts",
|
|
17
17
|
"main": "dist/src/index.js",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@flink-app/email-plugin": "^0.6.
|
|
19
|
+
"@flink-app/email-plugin": "^0.6.5",
|
|
20
20
|
"@flink-app/jwt-auth-plugin": "^0.6.1",
|
|
21
21
|
"@flink-app/management-api-plugin": "^0.6.0",
|
|
22
22
|
"@flink-app/sms-plugin": "^0.6.0",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ts-node": "^9.1.1",
|
|
31
31
|
"typescript": "^4.2.4"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "677244548e84f65f0709312010345e9e309d2e28"
|
|
34
34
|
}
|
package/src/coreFunctions.ts
CHANGED
|
@@ -281,12 +281,21 @@ export async function passwordResetStart(
|
|
|
281
281
|
lifeTime?: string
|
|
282
282
|
): Promise<UserPasswordResetStartRes> {
|
|
283
283
|
const user = await repo.getOne({ username: username.toLowerCase() });
|
|
284
|
+
|
|
285
|
+
const fakepayload = {
|
|
286
|
+
type: "passwordReset",
|
|
287
|
+
username: username.toLocaleLowerCase(),
|
|
288
|
+
};
|
|
289
|
+
const fakeToken = jsonwebtoken.sign(fakepayload, "fake_payload", { expiresIn: lifeTime });
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
284
293
|
if (user == null) {
|
|
285
|
-
return { status: "userNotFound" };
|
|
294
|
+
return { status: "userNotFound", passwordResetToken : fakeToken };
|
|
286
295
|
}
|
|
287
296
|
|
|
288
297
|
if (user.authentificationMethod != "password") {
|
|
289
|
-
return { status: "userNotFound" };
|
|
298
|
+
return { status: "userNotFound", passwordResetToken : fakeToken };
|
|
290
299
|
}
|
|
291
300
|
|
|
292
301
|
if (numberOfDigits == null) numberOfDigits = 6;
|
|
@@ -7,67 +7,59 @@ import { UserPasswordResetStartReq } from "../schemas/UserPasswordResetStartReq"
|
|
|
7
7
|
import { UserPasswordResetStartResPublic } from "../schemas/UserPasswordResetStartResPublic";
|
|
8
8
|
|
|
9
9
|
const postPasswordResetStartHandler: Handler<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
FlinkContext<genericAuthContext & emailPluginContext>,
|
|
11
|
+
UserPasswordResetStartReq,
|
|
12
|
+
UserPasswordResetStartResPublic
|
|
13
13
|
> = async ({ ctx, req, origin }) => {
|
|
14
|
-
|
|
15
|
-
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
14
|
+
let pluginName = origin || "genericAuthPlugin";
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
return internalServerError(
|
|
19
|
-
"Email plugin have to be initialized to use /password/reset"
|
|
20
|
-
);
|
|
21
|
-
}
|
|
16
|
+
const genericAuthPlugin = (<any>ctx.plugins)[pluginName] as genericAuthContext["genericAuthPlugin"];
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
return internalServerError(
|
|
25
|
-
"Password reset settings is needed to use /password/reset"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
18
|
+
let repo = ctx.repos[genericAuthPlugin.repoName];
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
if (ctx.plugins.emailPlugin?.client == null) {
|
|
21
|
+
return internalServerError("Email plugin have to be initialized to use /password/reset");
|
|
22
|
+
}
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
if (!genericAuthPlugin.passwordResetSettings) {
|
|
25
|
+
return internalServerError("Password reset settings is needed to use /password/reset");
|
|
26
|
+
}
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
repo,
|
|
36
|
-
<JwtAuthPlugin>ctx.auth,
|
|
37
|
-
jwtSecret,
|
|
38
|
-
req.body.username,
|
|
39
|
-
numberOfDigits,
|
|
40
|
-
lifeTime
|
|
41
|
-
);
|
|
28
|
+
const { jwtSecret, numberOfDigits, lifeTime } = genericAuthPlugin.passwordResetSettings.code;
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
return { data: { status: resp.status } };
|
|
45
|
-
}
|
|
30
|
+
const resp = await genericAuthPlugin.passwordResetStart(repo, <JwtAuthPlugin>ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime);
|
|
46
31
|
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
if (resp.status != "success") {
|
|
33
|
+
return { data: { status: "success", passwordResetToken: resp.passwordResetToken } };
|
|
34
|
+
}
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
const emailCtx = {
|
|
37
|
+
code: resp.code,
|
|
38
|
+
passwordResetToken: resp.passwordResetToken,
|
|
39
|
+
username: req.body.username,
|
|
40
|
+
profile: resp.profile,
|
|
41
|
+
};
|
|
56
42
|
|
|
57
|
-
|
|
58
|
-
const html = Handlebars.compile(emailSettings.html)(emailCtx);
|
|
59
|
-
const email = req.body.username;
|
|
43
|
+
let emailSettings = genericAuthPlugin.passwordResetSettings.email;
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
subject,
|
|
65
|
-
html,
|
|
66
|
-
});
|
|
45
|
+
if (typeof emailSettings == "function") {
|
|
46
|
+
emailSettings = emailSettings(emailCtx);
|
|
47
|
+
}
|
|
67
48
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
49
|
+
const subject = Handlebars.compile(emailSettings.subject)(emailCtx);
|
|
50
|
+
const html = Handlebars.compile(emailSettings.html)(emailCtx);
|
|
51
|
+
const email = req.body.username;
|
|
52
|
+
|
|
53
|
+
await ctx.plugins.emailPlugin.client.send({
|
|
54
|
+
from: emailSettings.from_address,
|
|
55
|
+
to: [email],
|
|
56
|
+
subject,
|
|
57
|
+
html,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
data: { status: "success", passwordResetToken: resp.passwordResetToken },
|
|
62
|
+
};
|
|
71
63
|
};
|
|
72
64
|
|
|
73
65
|
export default postPasswordResetStartHandler;
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { UserProfile } from "./UserProfile";
|
|
2
|
+
|
|
3
|
+
interface EmailConfig {
|
|
3
4
|
from_address: string;
|
|
4
5
|
subject: string;
|
|
5
6
|
html: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface EmailCtx {
|
|
10
|
+
code?: string;
|
|
11
|
+
passwordResetToken?: string;
|
|
12
|
+
username: string;
|
|
13
|
+
profile?: UserProfile;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UserPasswordResetSettings {
|
|
17
|
+
email: EmailConfig | ((emailCtx: EmailCtx) => EmailConfig);
|
|
18
|
+
code: {
|
|
19
|
+
numberOfDigits: number;
|
|
20
|
+
lifeTime: string;
|
|
21
|
+
jwtSecret: string;
|
|
22
|
+
};
|
|
23
|
+
enablePasswordResetForm?: boolean;
|
|
24
|
+
passwordResetForm?: string;
|
|
14
25
|
}
|