log
This commit is contained in:
parent
f9fce4ba25
commit
8e0de97b78
21 changed files with 637 additions and 210 deletions
|
|
@ -3,15 +3,13 @@ import { createDecoder, createVerifier } from "fast-jwt";
|
|||
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import { addLogSequence } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "./user";
|
||||
|
||||
if (!process.env.AUTH_PUBLIC_KEY && !process.env.AUTH_REALM_URL) {
|
||||
throw new Error("Require keycloak AUTH_PUBLIC_KEY or AUTH_REALM_URL.");
|
||||
}
|
||||
if (
|
||||
process.env.AUTH_PUBLIC_KEY &&
|
||||
process.env.AUTH_REALM_URL &&
|
||||
!process.env.AUTH_PREFERRED_MODE
|
||||
) {
|
||||
if (process.env.AUTH_PUBLIC_KEY && process.env.AUTH_REALM_URL && !process.env.AUTH_PREFERRED_MODE) {
|
||||
throw new Error(
|
||||
"AUTH_PREFFERRED must be specified if AUTH_PUBLIC_KEY and AUTH_REALM_URL is provided.",
|
||||
);
|
||||
|
|
@ -26,7 +24,7 @@ const jwtVerify = createVerifier({
|
|||
const jwtDecode = createDecoder();
|
||||
|
||||
export async function expressAuthentication(
|
||||
request: express.Request,
|
||||
request: RequestWithUser,
|
||||
securityName: string,
|
||||
_scopes?: string[],
|
||||
) {
|
||||
|
|
@ -56,6 +54,18 @@ export async function expressAuthentication(
|
|||
if (process.env.AUTH_PUBLIC_KEY) payload = await verifyOffline(token);
|
||||
break;
|
||||
}
|
||||
if (!request.app.locals.logData) {
|
||||
request.app.locals.logData = {};
|
||||
}
|
||||
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Query Data.",
|
||||
// });
|
||||
request.app.locals.logData.userId = payload.sub;
|
||||
request.app.locals.logData.userName = payload.name;
|
||||
request.app.locals.logData.user = payload.preferred_username;
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue