mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 15:33:12 +09:00
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:
1 parent
6af25e085c
commit
a5c7eb3a27
7 files changed
+20
-21
No files matched your search
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const fs = require("fs-extra");
|
||||
const jwt = require("jsonwebtoken");
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
@@ -83,6 +84,20 @@ class UserManager {
|
||||
this.users.set(name, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign access token for the given user name
|
||||
*
|
||||
* @param {string} name - user name to sign token for
|
||||
* @returns {string} JWT access token for the user.
|
||||
*/
|
||||
signUserToken(name) {
|
||||
return jwt.sign(
|
||||
{ aud: "user", user: name },
|
||||
Buffer.from(this._config.get("controller.auth_secret"), "base64")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UserManager;
|
||||
Reference in new issue
Block a user