feat: inject sessionId for logging purpose
This commit is contained in:
parent
e3e44d03b5
commit
cd47863f2a
2 changed files with 10 additions and 3 deletions
|
|
@ -10,8 +10,14 @@ export async function expressAuthentication(
|
|||
) {
|
||||
switch (securityName) {
|
||||
case "keycloak":
|
||||
return keycloakAuth(request, scopes);
|
||||
const authData = await keycloakAuth(request, scopes);
|
||||
request.app.locals.logData.sessionId = authData.session_state;
|
||||
return authData;
|
||||
default:
|
||||
throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Unknown how to verify identity.", "unknowHowToVerify");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_IMPLEMENTED,
|
||||
"Unknown how to verify identity.",
|
||||
"unknowHowToVerify",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NextFunction, Request, Response } from "express";
|
||||
import elasticsearch from "../services/elasticsearch";
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
if (!process.env.ELASTICSEARCH_INDEX) {
|
||||
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
||||
|
|
@ -50,7 +51,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
host: req.hostname,
|
||||
sessionId: req.headers["x-session-id"],
|
||||
rtId: req.headers["x-rtid"],
|
||||
tId: req.headers["x-tid"],
|
||||
tId: randomUUID(),
|
||||
method: req.method,
|
||||
endpoint: req.url,
|
||||
responseCode: res.statusCode,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue