Move user token signing to UserManager

Only the controller has access to the secret needed to sign user tokens
so it makes sense for the user signing code to live in the controller.
This saves about 20ms on the time ctl takes to start up due to lib no
longer needing to import jsonwebtoken.
This commit is contained in:
Hornwitser committed 2023-07-28 16:03:29 +02:00
1 parent 6af25e085c
commit a5c7eb3a27
7 files changed
+20 -21

No files matched your search

+3 -2
View File
@@ -130,7 +130,7 @@ async function handleBootstrapCommand(args, controllerConfig) {
return;
}
// eslint-disable-next-line no-console
console.log(user.createToken(controllerConfig.get("controller.auth_secret")));
console.log(userManager.signUserToken(user.name));
} else if (subCommand === "generate-host-token") {
// eslint-disable-next-line no-console
@@ -151,7 +151,8 @@ async function handleBootstrapCommand(args, controllerConfig) {
controlConfig.set("control.controller_url", Controller.calculateControllerUrl(controllerConfig));
controlConfig.set(
"control.controller_token", admin.createToken(controllerConfig.get("controller.auth_secret"))
"control.controller_token",
userManager.signUserToken(admin.name),
);
let content = JSON.stringify(controlConfig.serialize(), null, 4);