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

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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
1
+ // Generated Mon May 22 2023 15:57:15 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
1
+ // Generated Mon May 22 2023 15:57:15 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
1
+ // Generated Mon May 22 2023 15:57:14 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 Sat May 13 2023 14:44:47 GMT+0200 (Central European Summer Time)
33
+ // Generated Mon May 22 2023 15:57:18 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
1
+ // Generated Mon May 22 2023 15:57:15 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
4
+ // Generated Mon May 22 2023 15:57:15 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
4
+ // Generated Mon May 22 2023 15:57:15 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
4
+ // Generated Mon May 22 2023 15:57:14 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 Sat May 13 2023 14:44:46 GMT+0200 (Central European Summer Time)
3
+ // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("./generatedJobs");
@@ -10,7 +10,7 @@ import { UserPasswordResetCompleteRes } from "./schemas/UserPasswordResetComplet
10
10
  import { GenericAuthsmsOptions } from "./genericAuthPluginOptions";
11
11
  export declare function getJtwTokenPlugin(secret: string, rolePermissions?: {
12
12
  [role: string]: string[];
13
- }, passwordPolicy?: RegExp): JwtAuthPlugin;
13
+ }, passwordPolicy?: RegExp, tokenTTL?: number): JwtAuthPlugin;
14
14
  export declare function createUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string, authentificationMethod: "password" | "sms", roles: string[], profile: UserProfile, createPasswordHashAndSaltMethod?: {
15
15
  (password: string): Promise<{
16
16
  hash: string;
@@ -42,7 +42,7 @@ 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
43
  var jwt_auth_plugin_1 = require("@flink-app/jwt-auth-plugin");
44
44
  var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
45
- function getJtwTokenPlugin(secret, rolePermissions, passwordPolicy) {
45
+ function getJtwTokenPlugin(secret, rolePermissions, passwordPolicy, tokenTTL) {
46
46
  if (passwordPolicy == undefined) {
47
47
  passwordPolicy = /.{1,}$/;
48
48
  }
@@ -66,6 +66,7 @@ function getJtwTokenPlugin(secret, rolePermissions, passwordPolicy) {
66
66
  },
67
67
  passwordPolicy: passwordPolicy,
68
68
  rolePermissions: rolePermissions,
69
+ tokenTTL: tokenTTL
69
70
  });
70
71
  }
71
72
  exports.getJtwTokenPlugin = getJtwTokenPlugin;
@@ -45,37 +45,33 @@ 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, genericAuthPlugin, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp, emailCtx, emailSettings, subject, html, email;
48
+ var pluginName, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp, emailSettings, emailCtx, 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
- genericAuthPlugin = ctx.plugins[pluginName];
55
- repo = ctx.repos[genericAuthPlugin.repoName];
54
+ repo = ctx.repos[ctx.plugins[pluginName].repoName];
56
55
  if (((_c = ctx.plugins.emailPlugin) === null || _c === void 0 ? void 0 : _c.client) == null) {
57
56
  return [2 /*return*/, flink_1.internalServerError("Email plugin have to be initialized to use /password/reset")];
58
57
  }
59
- if (!genericAuthPlugin.passwordResetSettings) {
58
+ if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
60
59
  return [2 /*return*/, flink_1.internalServerError("Password reset settings is needed to use /password/reset")];
61
60
  }
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)];
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)];
64
63
  case 1:
65
64
  resp = _d.sent();
66
65
  if (resp.status != "success") {
67
66
  return [2 /*return*/, { data: { status: resp.status } }];
68
67
  }
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
- }
79
75
  subject = handlebars_1.default.compile(emailSettings.subject)(emailCtx);
80
76
  html = handlebars_1.default.compile(emailSettings.html)(emailCtx);
81
77
  email = req.body.username;
@@ -1,17 +1,9 @@
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
- }
13
1
  export interface UserPasswordResetSettings {
14
- email: EmailConfig | ((emailCtx: EmailCtx) => EmailConfig);
2
+ email: {
3
+ from_address: string;
4
+ subject: string;
5
+ html: string;
6
+ };
15
7
  code: {
16
8
  numberOfDigits: number;
17
9
  lifeTime: string;
@@ -20,4 +12,3 @@ export interface UserPasswordResetSettings {
20
12
  enablePasswordResetForm?: boolean;
21
13
  passwordResetForm?: string;
22
14
  }
23
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/generic-auth-plugin",
3
- "version": "0.6.1-alpha.0",
3
+ "version": "0.6.1",
4
4
  "description": "Flink plugin that provides a generic user authentification solution.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -17,7 +17,7 @@
17
17
  "main": "dist/src/index.js",
18
18
  "dependencies": {
19
19
  "@flink-app/email-plugin": "^0.6.0",
20
- "@flink-app/jwt-auth-plugin": "^0.6.0",
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",
23
23
  "handlebars": "^4.7.7",
@@ -30,5 +30,5 @@
30
30
  "ts-node": "^9.1.1",
31
31
  "typescript": "^4.2.4"
32
32
  },
33
- "gitHead": "f1abcb3fcc65d06feb68dccf873399a18618bb8d"
33
+ "gitHead": "86e5a311e8945c87f32d038a63658483076ffcff"
34
34
  }
@@ -12,7 +12,7 @@ import { UserPasswordResetCompleteRes } from "./schemas/UserPasswordResetComplet
12
12
  import jsonwebtoken from "jsonwebtoken";
13
13
  import { GenericAuthsmsOptions } from "./genericAuthPluginOptions";
14
14
 
15
- export function getJtwTokenPlugin(secret: string, rolePermissions?: { [role: string]: string[] }, passwordPolicy?: RegExp) {
15
+ export function getJtwTokenPlugin(secret: string, rolePermissions?: { [role: string]: string[] }, passwordPolicy?: RegExp, tokenTTL? : number) {
16
16
  if (passwordPolicy == undefined) {
17
17
  passwordPolicy = /.{1,}$/;
18
18
  }
@@ -36,6 +36,7 @@ export function getJtwTokenPlugin(secret: string, rolePermissions?: { [role: str
36
36
  },
37
37
  passwordPolicy,
38
38
  rolePermissions,
39
+ tokenTTL
39
40
  });
40
41
  }
41
42
 
@@ -7,59 +7,67 @@ 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";
14
+ let pluginName = origin || "genericAuthPlugin";
15
+ let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
15
16
 
16
- const genericAuthPlugin = (<any>ctx.plugins)[pluginName] as genericAuthContext["genericAuthPlugin"];
17
+ if (ctx.plugins.emailPlugin?.client == null) {
18
+ return internalServerError(
19
+ "Email plugin have to be initialized to use /password/reset"
20
+ );
21
+ }
17
22
 
18
- let repo = ctx.repos[genericAuthPlugin.repoName];
23
+ if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
24
+ return internalServerError(
25
+ "Password reset settings is needed to use /password/reset"
26
+ );
27
+ }
19
28
 
20
- if (ctx.plugins.emailPlugin?.client == null) {
21
- return internalServerError("Email plugin have to be initialized to use /password/reset");
22
- }
29
+ const { jwtSecret, numberOfDigits, lifeTime } =
30
+ (<any>ctx.plugins)[pluginName].passwordResetSettings.code;
23
31
 
24
- if (!genericAuthPlugin.passwordResetSettings) {
25
- return internalServerError("Password reset settings is needed to use /password/reset");
26
- }
32
+
27
33
 
28
- const { jwtSecret, numberOfDigits, lifeTime } = genericAuthPlugin.passwordResetSettings.code;
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
+ );
29
42
 
30
- const resp = await genericAuthPlugin.passwordResetStart(repo, <JwtAuthPlugin>ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime);
43
+ if (resp.status != "success") {
44
+ return { data: { status: resp.status } };
45
+ }
31
46
 
32
- if (resp.status != "success") {
33
- return { data: { status: resp.status } };
34
- }
47
+ const emailSettings =
48
+ (<any>ctx.plugins)[pluginName].passwordResetSettings.email;
35
49
 
36
- const emailCtx = {
37
- code: resp.code,
38
- passwordResetToken: resp.passwordResetToken,
39
- username: req.body.username,
40
- profile: resp.profile,
41
- };
50
+ const emailCtx = {
51
+ code: resp.code,
52
+ passwordResetToken: resp.passwordResetToken,
53
+ username: req.body.username,
54
+ profile: resp.profile,
55
+ };
42
56
 
43
- let emailSettings = genericAuthPlugin.passwordResetSettings.email;
57
+ const subject = Handlebars.compile(emailSettings.subject)(emailCtx);
58
+ const html = Handlebars.compile(emailSettings.html)(emailCtx);
59
+ const email = req.body.username;
44
60
 
45
- if (typeof emailSettings == "function") {
46
- emailSettings = emailSettings(emailCtx);
47
- }
61
+ await ctx.plugins.emailPlugin.client.send({
62
+ from: emailSettings.from_address,
63
+ to: [email],
64
+ subject,
65
+ html,
66
+ });
48
67
 
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
- };
68
+ return {
69
+ data: { status: "success", passwordResetToken: resp.passwordResetToken },
70
+ };
63
71
  };
64
72
 
65
73
  export default postPasswordResetStartHandler;
@@ -1,25 +1,14 @@
1
- import { UserProfile } from "./UserProfile";
2
-
3
- interface EmailConfig {
1
+ export interface UserPasswordResetSettings {
2
+ email: {
4
3
  from_address: string;
5
4
  subject: string;
6
5
  html: 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;
6
+ };
7
+ code: {
8
+ numberOfDigits: number;
9
+ lifeTime: string;
10
+ jwtSecret: string;
11
+ };
12
+ enablePasswordResetForm?: boolean;
13
+ passwordResetForm?: string;
25
14
  }