@flink-app/generic-auth-plugin 0.6.2 → 0.6.3

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.
@@ -1,4 +1,4 @@
1
- // Generated Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 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";
@@ -1,4 +1,4 @@
1
- // Generated Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
2
2
  import { autoRegisteredJobs } from "@flink-app/flink";
3
3
  export const jobs = [];
4
4
  autoRegisteredJobs.push(...jobs);
@@ -1,4 +1,4 @@
1
- // Generated Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 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 Fri Jun 16 2023 09:56:42 GMT+0200 (Central European Summer Time)
32
+ // Generated Wed Aug 16 2023 08:50:01 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,4 +1,4 @@
1
- // Generated Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
2
2
  import "./generatedHandlers";
3
3
  import "./generatedRepos";
4
4
  import "./generatedJobs";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlers = void 0;
4
- // Generated Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
4
+ // Generated Wed Aug 16 2023 08:49:59 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 Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
4
+ // Generated Wed Aug 16 2023 08:49:59 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 Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
4
+ // Generated Wed Aug 16 2023 08:49:59 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);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Generated Fri Jun 16 2023 09:56:40 GMT+0200 (Central European Summer Time)
3
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer 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, emailSettings, emailCtx, subject, html, email;
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
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
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 (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
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 = ctx.plugins[pluginName].passwordResetSettings.code, jwtSecret = _b.jwtSecret, numberOfDigits = _b.numberOfDigits, lifeTime = _b.lifeTime;
62
- return [4 /*yield*/, ctx.plugins.genericAuthPlugin.passwordResetStart(repo, ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime)];
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.status } }];
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.2",
3
+ "version": "0.6.3",
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": "^4.2.4"
32
32
  },
33
- "gitHead": "25e6eb796366ff9801118b760c722869f1c09620"
33
+ "gitHead": "0ed59ee7618fda029a8979cc9e4c88894d93548e"
34
34
  }
@@ -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
- FlinkContext<genericAuthContext & emailPluginContext>,
11
- UserPasswordResetStartReq,
12
- UserPasswordResetStartResPublic
10
+ FlinkContext<genericAuthContext & emailPluginContext>,
11
+ UserPasswordResetStartReq,
12
+ UserPasswordResetStartResPublic
13
13
  > = async ({ ctx, req, origin }) => {
14
- let pluginName = origin || "genericAuthPlugin";
15
- let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
14
+ let pluginName = origin || "genericAuthPlugin";
16
15
 
17
- if (ctx.plugins.emailPlugin?.client == null) {
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
- if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
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
- const { jwtSecret, numberOfDigits, lifeTime } =
30
- (<any>ctx.plugins)[pluginName].passwordResetSettings.code;
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
- const resp = await ctx.plugins.genericAuthPlugin.passwordResetStart(
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
- if (resp.status != "success") {
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
- const emailSettings =
48
- (<any>ctx.plugins)[pluginName].passwordResetSettings.email;
32
+ if (resp.status != "success") {
33
+ return { data: { status: "success", passwordResetToken: resp.passwordResetToken } };
34
+ }
49
35
 
50
- const emailCtx = {
51
- code: resp.code,
52
- passwordResetToken: resp.passwordResetToken,
53
- username: req.body.username,
54
- profile: resp.profile,
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
- const subject = Handlebars.compile(emailSettings.subject)(emailCtx);
58
- const html = Handlebars.compile(emailSettings.html)(emailCtx);
59
- const email = req.body.username;
43
+ let emailSettings = genericAuthPlugin.passwordResetSettings.email;
60
44
 
61
- await ctx.plugins.emailPlugin.client.send({
62
- from: emailSettings.from_address,
63
- to: [email],
64
- subject,
65
- html,
66
- });
45
+ if (typeof emailSettings == "function") {
46
+ emailSettings = emailSettings(emailCtx);
47
+ }
67
48
 
68
- return {
69
- data: { status: "success", passwordResetToken: resp.passwordResetToken },
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
- export interface UserPasswordResetSettings {
2
- email: {
1
+ import { UserProfile } from "./UserProfile";
2
+
3
+ interface EmailConfig {
3
4
  from_address: string;
4
5
  subject: string;
5
6
  html: string;
6
- };
7
- code: {
8
- numberOfDigits: number;
9
- lifeTime: string;
10
- jwtSecret: string;
11
- };
12
- enablePasswordResetForm?: boolean;
13
- passwordResetForm?: string;
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
  }