@gen-epix/oidc-mock-server 0.0.5 → 0.0.7
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/bin/oidc-mock-server.js +65 -7
- package/package.json +4 -4
package/bin/oidc-mock-server.js
CHANGED
|
@@ -4,6 +4,7 @@ import { OAuth2Server } from 'oauth2-mock-server';
|
|
|
4
4
|
import basicAuth from 'basic-auth';
|
|
5
5
|
import { findGitRootPath } from '@gen-epix/tools-lib';
|
|
6
6
|
import { existsSync, readFileSync } from 'fs';
|
|
7
|
+
import { json, urlencoded } from 'express';
|
|
7
8
|
|
|
8
9
|
const DEFAULT_PORT = 5443;
|
|
9
10
|
const DEFAULT_TOKEN_TIME_OUT_SECONDS = 3600;
|
|
@@ -25,10 +26,6 @@ if (!existsSync(certPemPath)) {
|
|
|
25
26
|
process.exit(1);
|
|
26
27
|
}
|
|
27
28
|
const config = JSON.parse(readFileSync(configFilePath, "utf-8"));
|
|
28
|
-
if (!config.user || !config.user.email || !config.user.sub || !config.user.first_name || !config.user.last_name) {
|
|
29
|
-
console.error("Invalid configuration: user, email, and sub are required.");
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
29
|
if (!config.port) {
|
|
33
30
|
console.warn(`Port not specified, using default port ${DEFAULT_PORT}.`);
|
|
34
31
|
}
|
|
@@ -38,7 +35,7 @@ if (!config.token_time_out_seconds) {
|
|
|
38
35
|
if (!config.scope) {
|
|
39
36
|
console.warn(`Scope not specified, using default scope "${DEFAULT_SCOPE}".`);
|
|
40
37
|
}
|
|
41
|
-
|
|
38
|
+
let user = { ...config.user ?? {} };
|
|
42
39
|
const PORT = config.port ?? DEFAULT_PORT;
|
|
43
40
|
const TOKEN_TIME_OUT_SECONDS = config.token_time_out_seconds ?? DEFAULT_TOKEN_TIME_OUT_SECONDS;
|
|
44
41
|
const SCOPE = config.scope ?? DEFAULT_SCOPE;
|
|
@@ -77,13 +74,13 @@ const start = async () => {
|
|
|
77
74
|
token.payload.aud = clientId;
|
|
78
75
|
token.payload.exp = exp();
|
|
79
76
|
token.payload.scope = SCOPE;
|
|
80
|
-
const userCopy = { ...
|
|
77
|
+
const userCopy = { ...user };
|
|
81
78
|
delete userCopy.email;
|
|
82
79
|
Object.assign(token.payload, userCopy);
|
|
83
80
|
});
|
|
84
81
|
server.service.on("beforeUserinfo", (userInfoResponse) => {
|
|
85
82
|
console.log("Serving userinfo");
|
|
86
|
-
userInfoResponse.body =
|
|
83
|
+
userInfoResponse.body = user;
|
|
87
84
|
userInfoResponse.statusCode = 200;
|
|
88
85
|
});
|
|
89
86
|
server.service.on("beforeIntrospect", (introspectResponse) => {
|
|
@@ -95,6 +92,67 @@ const start = async () => {
|
|
|
95
92
|
exp: exp()
|
|
96
93
|
};
|
|
97
94
|
});
|
|
95
|
+
const requestHandler = server.service.requestHandler;
|
|
96
|
+
requestHandler.use(json());
|
|
97
|
+
requestHandler.use(urlencoded({ extended: true }));
|
|
98
|
+
requestHandler.post("/set-user", (req, res) => {
|
|
99
|
+
try {
|
|
100
|
+
const updatedUser = req.body;
|
|
101
|
+
if (!updatedUser || Object.keys(updatedUser).length === 0) {
|
|
102
|
+
return res.status(400).json({
|
|
103
|
+
error: "Bad Request",
|
|
104
|
+
message: "Request body must contain at least one user field to update"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (updatedUser.email !== void 0) {
|
|
108
|
+
if (typeof updatedUser.email !== "string" || !updatedUser.email.trim()) {
|
|
109
|
+
return res.status(400).json({
|
|
110
|
+
error: "Bad Request",
|
|
111
|
+
message: "Email must be a non-empty string"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
user.email = updatedUser.email.trim();
|
|
115
|
+
}
|
|
116
|
+
if (updatedUser.sub !== void 0) {
|
|
117
|
+
if (typeof updatedUser.sub !== "string" || !updatedUser.sub.trim()) {
|
|
118
|
+
return res.status(400).json({
|
|
119
|
+
error: "Bad Request",
|
|
120
|
+
message: "Sub must be a non-empty string"
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
user.sub = updatedUser.sub.trim();
|
|
124
|
+
}
|
|
125
|
+
if (updatedUser.first_name !== void 0) {
|
|
126
|
+
if (typeof updatedUser.first_name !== "string" || !updatedUser.first_name.trim()) {
|
|
127
|
+
return res.status(400).json({
|
|
128
|
+
error: "Bad Request",
|
|
129
|
+
message: "First name must be a non-empty string"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
user.first_name = updatedUser.first_name.trim();
|
|
133
|
+
}
|
|
134
|
+
if (updatedUser.last_name !== void 0) {
|
|
135
|
+
if (typeof updatedUser.last_name !== "string" || !updatedUser.last_name.trim()) {
|
|
136
|
+
return res.status(400).json({
|
|
137
|
+
error: "Bad Request",
|
|
138
|
+
message: "Last name must be a non-empty string"
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
user.last_name = updatedUser.last_name.trim();
|
|
142
|
+
}
|
|
143
|
+
console.log("User updated:", user);
|
|
144
|
+
res.status(200).json({
|
|
145
|
+
message: "User updated successfully",
|
|
146
|
+
user: { ...user }
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error("Error updating user:", error);
|
|
150
|
+
res.status(500).json({
|
|
151
|
+
error: "Internal Server Error",
|
|
152
|
+
message: "Failed to update user"
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
98
156
|
await server.start(PORT, "127.0.0.1");
|
|
99
157
|
};
|
|
100
158
|
start().then(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gen-epix/oidc-mock-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@gen-epix/tools-lib": "*",
|
|
30
30
|
"basic-auth": "2.0.1",
|
|
31
|
-
"oauth2-mock-server": "8.2.
|
|
31
|
+
"oauth2-mock-server": "8.2.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@gen-epix/eslint-config": "*",
|
|
35
35
|
"@gen-epix/typescript-config": "*",
|
|
36
36
|
"@types/basic-auth": "1.1.8",
|
|
37
|
+
"@types/express": "5.0.6",
|
|
37
38
|
"@types/node": "24.10.1",
|
|
38
|
-
"eslint": "9.39.1",
|
|
39
39
|
"nodemon": "3.1.11",
|
|
40
40
|
"typescript": "5.9.3",
|
|
41
41
|
"rimraf": "6.1.2",
|
|
42
|
-
"rollup": "4.
|
|
42
|
+
"rollup": "4.57.1",
|
|
43
43
|
"rollup-plugin-esbuild": "6.2.1"
|
|
44
44
|
}
|
|
45
45
|
}
|