godprotocol 2.3.1 → 2.3.12
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/Godprotocol.js
CHANGED
|
@@ -47,7 +47,7 @@ class GodProtocol {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
add_router = async (version, routes, opts = {}) => {
|
|
50
|
-
if (typeof routes === "function") routes = await routes();
|
|
50
|
+
if (typeof routes === "function" && !opts.is_old) routes = await routes();
|
|
51
51
|
|
|
52
52
|
if (opts.is_old) {
|
|
53
53
|
await this.route_table.init_version(version, { is_old: true });
|
package/package.json
CHANGED
|
@@ -251,7 +251,12 @@ class Headers extends Services {
|
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
handle_security = async (name, request) => {
|
|
254
|
-
|
|
254
|
+
let config;
|
|
255
|
+
if (this.active_version === "*") {
|
|
256
|
+
let version = this.versions[this.active_version];
|
|
257
|
+
|
|
258
|
+
config = version.config;
|
|
259
|
+
}
|
|
255
260
|
|
|
256
261
|
let route = await this.get_route(name);
|
|
257
262
|
|
|
@@ -260,14 +265,15 @@ class Headers extends Services {
|
|
|
260
265
|
}
|
|
261
266
|
if (!route?.config?.security?.length) return true;
|
|
262
267
|
|
|
263
|
-
|
|
268
|
+
config = route.config;
|
|
269
|
+
if (!this.check_security(config.security, request)) {
|
|
264
270
|
// debug("Unauthorized access attempt to route:", name);
|
|
265
271
|
return {
|
|
266
272
|
ok: false,
|
|
267
273
|
status: 401,
|
|
268
274
|
message:
|
|
269
275
|
"Unauthorized: Missing required authentication headers of type(s): " +
|
|
270
|
-
|
|
276
|
+
config.security.join(", "),
|
|
271
277
|
};
|
|
272
278
|
}
|
|
273
279
|
|
|
@@ -277,7 +283,7 @@ class Headers extends Services {
|
|
|
277
283
|
if (authorisation) authorisation = authorisation.replace("Bearer ", "");
|
|
278
284
|
|
|
279
285
|
let val;
|
|
280
|
-
if (
|
|
286
|
+
if (config.security?.includes("auth_token")) {
|
|
281
287
|
if (authorisation?.startsWith("p")) {
|
|
282
288
|
val = await this.validate_api_key(authorisation);
|
|
283
289
|
} else
|
|
@@ -286,7 +292,7 @@ class Headers extends Services {
|
|
|
286
292
|
authorisation,
|
|
287
293
|
request,
|
|
288
294
|
);
|
|
289
|
-
} else if (
|
|
295
|
+
} else if (config.security?.includes("api_key")) {
|
|
290
296
|
val = await this.validate_api_key(api_key, authorisation);
|
|
291
297
|
}
|
|
292
298
|
|
|
@@ -44,7 +44,11 @@ class Route_table extends Headers {
|
|
|
44
44
|
load_routes = async (routes) => {
|
|
45
45
|
if (this.active_version === "*") {
|
|
46
46
|
this.versions[this.active_version] = {
|
|
47
|
-
handler: routes,
|
|
47
|
+
handler: routes.handler,
|
|
48
|
+
config: {
|
|
49
|
+
security: securities[config.security || "none"],
|
|
50
|
+
schema: routes.schema,
|
|
51
|
+
},
|
|
48
52
|
};
|
|
49
53
|
return;
|
|
50
54
|
}
|