@flink-app/generic-auth-plugin 0.5.3 → 0.6.1-alpha.0

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 Mon May 08 2023 10:08:54 GMT+0200 (Central European Summer Time)
1
+ // Generated Sat May 13 2023 14:44:46 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 Mon May 08 2023 10:08:55 GMT+0200 (Central European Summer Time)
1
+ // Generated Sat May 13 2023 14:44:46 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 Mon May 08 2023 10:08:54 GMT+0200 (Central European Summer Time)
1
+ // Generated Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
2
2
  import { autoRegisteredRepos } from "@flink-app/flink";
3
3
  export const repos = [];
4
4
  autoRegisteredRepos.push(...repos);
@@ -30,7 +30,7 @@ import { PutManagementUserRolesByUseridRes } from "../../src/schemas/Management/
30
30
  import { PutManagementUserUsernameByUseridReq } from "../../src/schemas/Management/PutUserUsernameByUseridReq";
31
31
  import { PutManagementUserUsernameByUseridRes } from "../../src/schemas/Management/PutUserUsernameByUseridRes";
32
32
 
33
- // Generated Mon May 08 2023 10:08:59 GMT+0200 (Central European Summer Time)
33
+ // Generated Sat May 13 2023 14:44:47 GMT+0200 (Central European Summer Time)
34
34
  export interface UserCreate_7_ReqSchema extends UserCreateReq {}
35
35
 
36
36
  export interface UserCreate_7_ResSchema extends UserCreateRes {}
package/.flink/start.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Generated Mon May 08 2023 10:08:55 GMT+0200 (Central European Summer Time)
1
+ // Generated Sat May 13 2023 14:44:46 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 Mon May 08 2023 10:08:54 GMT+0200 (Central European Summer Time)
4
+ // Generated Sat May 13 2023 14:44:46 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 Mon May 08 2023 10:08:55 GMT+0200 (Central European Summer Time)
4
+ // Generated Sat May 13 2023 14:44:46 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 Mon May 08 2023 10:08:54 GMT+0200 (Central European Summer Time)
4
+ // Generated Sat May 13 2023 14:44:46 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 Mon May 08 2023 10:08:55 GMT+0200 (Central European Summer Time)
3
+ // Generated Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("./generatedJobs");
@@ -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
67
  return [2 /*return*/, { data: { status: resp.status } }];
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.5.3",
3
+ "version": "0.6.1-alpha.0",
4
4
  "description": "Flink plugin that provides a generic user authentification solution.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -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.5.0",
20
- "@flink-app/jwt-auth-plugin": "^0.5.3",
21
- "@flink-app/management-api-plugin": "^0.5.2",
22
- "@flink-app/sms-plugin": "^0.5.0",
19
+ "@flink-app/email-plugin": "^0.6.0",
20
+ "@flink-app/jwt-auth-plugin": "^0.6.0",
21
+ "@flink-app/management-api-plugin": "^0.6.0",
22
+ "@flink-app/sms-plugin": "^0.6.0",
23
23
  "handlebars": "^4.7.7",
24
24
  "jsonwebtoken": "^8.5.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@flink-app/flink": "^0.5.0",
27
+ "@flink-app/flink": "^0.6.0",
28
28
  "@types/jsonwebtoken": "^8.5.2",
29
29
  "@types/node": "^15.6.2",
30
30
  "ts-node": "^9.1.1",
31
31
  "typescript": "^4.2.4"
32
32
  },
33
- "gitHead": "c5e47bae95b9e157f77936d7b8996a2534c26a3f"
33
+ "gitHead": "f1abcb3fcc65d06feb68dccf873399a18618bb8d"
34
34
  }
@@ -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: resp.status } };
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
  }