allow to revoke host tokens from web ui (#511)

* allow to revoke / restore host access from web ui

* refector to what is expected

* remove core.admin check on HostViewPage.tsx

* update core.host.revoke_token description
This commit is contained in:
Luciole authored and GitHub committed 2023-09-29 19:50:14 +02:00
1 parent 838170a9ff
commit e2dea35e02
11 files changed
+120 -10

No files matched your search

+11 -1
View File
@@ -147,12 +147,22 @@ function validateHostToken(req: Request, res: Response, next: any) {
}
try {
jwt.verify(
const tokenPayload = jwt.verify(
token,
Buffer.from(req.app.locals.controller.config.get("controller.auth_secret"), "base64"),
{ audience: "host" }
);
if (typeof tokenPayload === "string") {
throw new Error("unexpected JsonWebToken type");
}
let host = (req.app.locals.controller as Controller).hosts!.get(tokenPayload.host);
if (!host) {
throw new Error("invalid host");
}
if (!tokenPayload.iat || tokenPayload.iat < (host.token_valid_after??0)) {
throw new Error("invalid token");
}
} catch (err) {
res.sendStatus(401);
return;