@flink-app/generic-auth-plugin 0.3.0 → 0.3.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.
- package/.flink/generatedHandlers.ts +2 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.json +42 -2
- package/.flink/schemas/schemas.ts +9 -3
- package/.flink/start.ts +1 -1
- package/dist/.flink/generatedHandlers.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/schemas/schemas.d.ts +8 -2
- package/dist/.flink/schemas/schemas.json +42 -2
- package/dist/.flink/start.js +1 -1
- package/dist/src/coreFunctions.js +2 -2
- package/dist/src/handlers/Management/GetUserViewByUserid.d.ts +7 -0
- package/dist/src/handlers/Management/GetUserViewByUserid.js +80 -0
- package/dist/src/handlers/UserProfilePut.js +14 -3
- package/dist/src/management.d.ts +6 -0
- package/dist/src/management.js +17 -4
- package/dist/src/schemas/Management/GetUserViewByUseridReq.d.ts +2 -0
- package/dist/src/schemas/Management/GetUserViewByUseridReq.js +2 -0
- package/dist/src/schemas/Management/GetUserViewByUseridRes.d.ts +9 -0
- package/dist/src/schemas/Management/GetUserViewByUseridRes.js +2 -0
- package/package.json +3 -3
- package/readme.md +55 -0
- package/src/coreFunctions.ts +245 -270
- package/src/handlers/Management/GetUserViewByUserid.ts +38 -0
- package/src/handlers/UserCreate.ts +43 -55
- package/src/handlers/UserProfilePut.ts +8 -2
- package/src/management.ts +152 -136
- package/src/schemas/Management/GetUserViewByUseridReq.ts +3 -0
- package/src/schemas/Management/GetUserViewByUseridRes.ts +4 -0
|
@@ -1,68 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
badRequest,
|
|
3
|
-
conflict,
|
|
4
|
-
FlinkContext,
|
|
5
|
-
Handler,
|
|
6
|
-
internalServerError,
|
|
7
|
-
} from "@flink-app/flink";
|
|
1
|
+
import { badRequest, conflict, FlinkContext, Handler, internalServerError } from "@flink-app/flink";
|
|
8
2
|
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
9
3
|
import { genericAuthContext } from "../genericAuthContext";
|
|
10
4
|
import { UserCreateReq } from "../schemas/UserCreateReq";
|
|
11
5
|
import { UserCreateRes } from "../schemas/UserCreateRes";
|
|
12
6
|
|
|
13
|
-
const userCreateHandler: Handler<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
if (password == null) {
|
|
28
|
-
password = "";
|
|
29
|
-
}
|
|
30
|
-
let roles: string[] = [];
|
|
31
|
-
if (profile == null) profile = {};
|
|
7
|
+
const userCreateHandler: Handler<FlinkContext<genericAuthContext>, UserCreateReq, UserCreateRes> = async ({ ctx, req, origin }) => {
|
|
8
|
+
let { password, username, authentificationMethod, profile } = req.body;
|
|
9
|
+
if (authentificationMethod == null) {
|
|
10
|
+
authentificationMethod = "password";
|
|
11
|
+
}
|
|
12
|
+
if (authentificationMethod == "password" && password == null) {
|
|
13
|
+
return internalServerError("When using password as authentification method password must be supplied");
|
|
14
|
+
}
|
|
15
|
+
if (password == null) {
|
|
16
|
+
password = "";
|
|
17
|
+
}
|
|
18
|
+
let roles: string[] = [];
|
|
19
|
+
if (profile == null) profile = {};
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
let pluginName = origin || "genericAuthPlugin";
|
|
22
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
35
23
|
|
|
36
|
-
|
|
24
|
+
var re = <RegExp>(<any>ctx.plugins)[pluginName].usernameFormat;
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
if (!re.test(username)) {
|
|
27
|
+
return badRequest("Username does not meet requirements", "usernameError");
|
|
28
|
+
}
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
const createUserResponse = await ctx.plugins.genericAuthPlugin.createUser(
|
|
31
|
+
repo,
|
|
32
|
+
<JwtAuthPlugin>ctx.auth,
|
|
33
|
+
username,
|
|
34
|
+
password,
|
|
35
|
+
authentificationMethod,
|
|
36
|
+
roles,
|
|
37
|
+
profile,
|
|
38
|
+
ctx.plugins.genericAuthPlugin.createPasswordHashAndSaltMethod
|
|
39
|
+
);
|
|
40
|
+
if (createUserResponse.status != "success") {
|
|
41
|
+
switch (createUserResponse.status) {
|
|
42
|
+
case "error":
|
|
43
|
+
return internalServerError("Unknown error", createUserResponse.status);
|
|
44
|
+
case "passwordError":
|
|
45
|
+
return badRequest("Invalid password", createUserResponse.status);
|
|
46
|
+
case "userExists":
|
|
47
|
+
return conflict("User already exists", createUserResponse.status);
|
|
48
|
+
}
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
50
|
+
return {
|
|
51
|
+
data: createUserResponse,
|
|
52
|
+
status: 200,
|
|
53
|
+
};
|
|
66
54
|
};
|
|
67
55
|
|
|
68
56
|
export default userCreateHandler;
|
|
@@ -16,8 +16,14 @@ const putUserProfileHandler: Handler<
|
|
|
16
16
|
return notFound();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
const updatedProfile = {
|
|
21
|
+
...user.profile,
|
|
22
|
+
...req.body,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
await repo.updateOne(userId, { profile: updatedProfile });
|
|
21
27
|
|
|
22
28
|
user = await repo.getById(userId);
|
|
23
29
|
|
package/src/management.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ManagementApiModule,
|
|
3
|
-
ManagementApiType,
|
|
4
|
-
} from "@flink-app/management-api-plugin";
|
|
1
|
+
import { ManagementApiModule, ManagementApiType } from "@flink-app/management-api-plugin";
|
|
5
2
|
import { HttpMethod } from "@flink-app/flink";
|
|
6
3
|
import * as userCreateHandler from "./handlers/UserCreate";
|
|
7
4
|
import * as GetManagementUser from "./handlers/Management/GetUser";
|
|
@@ -11,145 +8,164 @@ import * as PutManagementUserProfileByUserid from "./handlers/Management/PutUser
|
|
|
11
8
|
import * as PutManagementUserUsernameByUserid from "./handlers/Management/PutUserUsernameByUserid";
|
|
12
9
|
import * as PutManagementUserRolesByUserid from "./handlers/Management/PutUserRolesByUserid";
|
|
13
10
|
import * as DeleteManagementUserByUserid from "./handlers/Management/DeleteUserByUserid";
|
|
11
|
+
import * as GetUserViewByUserid from "./handlers/Management/GetUserViewByUserid";
|
|
14
12
|
|
|
15
13
|
import * as PutUserProfileByUseridAppend from "./handlers/Management/PutUserProfileByUseridAppend";
|
|
16
14
|
import * as GetSchema from "./handlers/Management/GetSchema";
|
|
15
|
+
import { User } from ".";
|
|
16
|
+
import { GetManagementUserViewByUseridRes } from "./schemas/Management/GetUserViewByUseridRes";
|
|
17
17
|
|
|
18
18
|
export interface GetManagementModuleConfig {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
pluginId?: string;
|
|
20
|
+
profileSchema?: any;
|
|
21
|
+
ui: boolean;
|
|
22
|
+
userView?: {
|
|
23
|
+
getData(user: User): GetManagementUserViewByUseridRes;
|
|
24
|
+
};
|
|
25
|
+
uiSettings?: {
|
|
26
|
+
title: string;
|
|
27
|
+
enableUserDelete?: boolean;
|
|
28
|
+
enableUserCreate?: boolean;
|
|
29
|
+
enableUserEdit?: boolean;
|
|
30
|
+
enableUserView?: boolean;
|
|
31
|
+
};
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export const GetManagementModule = (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
endpoints: endpoints,
|
|
149
|
-
data : {
|
|
150
|
-
profileSchema : config.profileSchema
|
|
34
|
+
export const GetManagementModule = (config: GetManagementModuleConfig): ManagementApiModule => {
|
|
35
|
+
if (config.pluginId == null) config.pluginId = "genericAuthPlugin";
|
|
36
|
+
|
|
37
|
+
let endpoints: ManagementApiModule["endpoints"] = [];
|
|
38
|
+
endpoints.push({
|
|
39
|
+
routeProps: {
|
|
40
|
+
path: "",
|
|
41
|
+
method: HttpMethod.post,
|
|
42
|
+
origin: config.pluginId,
|
|
43
|
+
},
|
|
44
|
+
handler: userCreateHandler,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
endpoints.push({
|
|
48
|
+
routeProps: {
|
|
49
|
+
path: "",
|
|
50
|
+
method: HttpMethod.get,
|
|
51
|
+
origin: config.pluginId,
|
|
52
|
+
},
|
|
53
|
+
handler: GetManagementUser,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
endpoints.push({
|
|
57
|
+
routeProps: {
|
|
58
|
+
path: "/profile/schema",
|
|
59
|
+
method: HttpMethod.get,
|
|
60
|
+
origin: config.pluginId || "genericAuthPlugin",
|
|
61
|
+
},
|
|
62
|
+
handler: GetSchema,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
endpoints.push({
|
|
66
|
+
routeProps: {
|
|
67
|
+
path: "/:userid",
|
|
68
|
+
method: HttpMethod.get,
|
|
69
|
+
origin: config.pluginId,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
handler: GetManagementUserByUserid,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
endpoints.push({
|
|
76
|
+
routeProps: {
|
|
77
|
+
path: "/:userid/view",
|
|
78
|
+
method: HttpMethod.get,
|
|
79
|
+
origin: config.pluginId,
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
handler: GetUserViewByUserid,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
endpoints.push({
|
|
86
|
+
routeProps: {
|
|
87
|
+
path: "/:userid",
|
|
88
|
+
method: HttpMethod.delete,
|
|
89
|
+
origin: config.pluginId,
|
|
90
|
+
},
|
|
91
|
+
handler: DeleteManagementUserByUserid,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
endpoints.push({
|
|
95
|
+
routeProps: {
|
|
96
|
+
path: "/password/:userid",
|
|
97
|
+
method: HttpMethod.put,
|
|
98
|
+
origin: config.pluginId,
|
|
99
|
+
},
|
|
100
|
+
handler: PutManagementUserPasswordByUserid,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
endpoints.push({
|
|
104
|
+
routeProps: {
|
|
105
|
+
path: "/username/:userid",
|
|
106
|
+
method: HttpMethod.put,
|
|
107
|
+
origin: config.pluginId,
|
|
108
|
+
},
|
|
109
|
+
handler: PutManagementUserUsernameByUserid,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
endpoints.push({
|
|
113
|
+
routeProps: {
|
|
114
|
+
path: "/profile/:userid",
|
|
115
|
+
method: HttpMethod.put,
|
|
116
|
+
origin: config.pluginId,
|
|
117
|
+
},
|
|
118
|
+
handler: PutManagementUserProfileByUserid,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
endpoints.push({
|
|
122
|
+
routeProps: {
|
|
123
|
+
path: "/profile/:userid/append",
|
|
124
|
+
method: HttpMethod.put,
|
|
125
|
+
origin: config.pluginId,
|
|
126
|
+
},
|
|
127
|
+
handler: PutUserProfileByUseridAppend,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
endpoints.push({
|
|
131
|
+
routeProps: {
|
|
132
|
+
path: "/roles/:userid",
|
|
133
|
+
method: HttpMethod.put,
|
|
134
|
+
origin: config.pluginId,
|
|
135
|
+
},
|
|
136
|
+
handler: PutManagementUserRolesByUserid,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
let features: string[] = [];
|
|
140
|
+
|
|
141
|
+
if (config.uiSettings?.enableUserDelete == true) {
|
|
142
|
+
features.push("delete");
|
|
143
|
+
}
|
|
144
|
+
if (config.uiSettings?.enableUserCreate == true) {
|
|
145
|
+
features.push("create");
|
|
146
|
+
}
|
|
147
|
+
if (config.uiSettings?.enableUserEdit == true) {
|
|
148
|
+
features.push("edit");
|
|
149
|
+
}
|
|
150
|
+
if (config.uiSettings?.enableUserView == true) {
|
|
151
|
+
features.push("view");
|
|
151
152
|
}
|
|
152
|
-
};
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
let module: ManagementApiModule = {
|
|
155
|
+
id: config.pluginId || "user",
|
|
156
|
+
uiSettings: {
|
|
157
|
+
title: config.uiSettings?.title || "Users",
|
|
158
|
+
icon: "",
|
|
159
|
+
features,
|
|
160
|
+
},
|
|
161
|
+
ui: config.ui,
|
|
162
|
+
type: ManagementApiType.user,
|
|
163
|
+
endpoints: endpoints,
|
|
164
|
+
data: {
|
|
165
|
+
profileSchema: config.profileSchema,
|
|
166
|
+
userViewGetData: config.userView?.getData,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return module;
|
|
155
171
|
};
|