response-standardizer 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -6
- package/package.json +1 -1
- package/src/index.ts +7 -8
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ declare global {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
export declare const initKeycloak: (config: {
|
|
16
|
+
service?: string;
|
|
17
|
+
realm?: string;
|
|
18
|
+
}) => Promise<void>;
|
|
15
19
|
export declare const protect: (req: Request, res: Response, next: any) => void;
|
|
16
20
|
export declare const role: (allowedRoles: string[]) => (req: any, res: any, next: any) => void;
|
|
17
21
|
export declare const RestResponse: RestResponseFunctions;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { generateRequestId, getTimestamp } from "./utils.js";
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import jwt from "jsonwebtoken";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let KEYCLOAK_PUBLIC_KEY = null;
|
|
5
|
+
export const initKeycloak = async (config) => {
|
|
6
|
+
const KEYCLOAK_SERVICE = config.service ?? "localhost";
|
|
7
|
+
const KEYCLOAK_REALM = config.realm ?? "master";
|
|
8
|
+
const realmUrl = `http://${KEYCLOAK_SERVICE}/realms/${KEYCLOAK_REALM}`;
|
|
6
9
|
console.log(`Keycloak PublicKey Url: ${realmUrl}`);
|
|
7
10
|
const resp = await axios.get(realmUrl);
|
|
8
11
|
const key = resp.data.public_key;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const KEYCLOAK_PUBLIC_KEY = await getKeycloakPublicKey();
|
|
12
|
+
KEYCLOAK_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
|
|
13
|
+
};
|
|
13
14
|
export const protect = (req, res, next) => {
|
|
14
15
|
const authHeader = req.headers["authorization"];
|
|
15
16
|
if (!authHeader)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,17 +15,16 @@ declare global {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
async
|
|
20
|
-
const
|
|
18
|
+
let KEYCLOAK_PUBLIC_KEY: any = null;
|
|
19
|
+
export const initKeycloak = async (config: { service?: string; realm?: string }) => {
|
|
20
|
+
const KEYCLOAK_SERVICE = config.service ?? "localhost";
|
|
21
|
+
const KEYCLOAK_REALM = config.realm ?? "master";
|
|
22
|
+
const realmUrl = `http://${KEYCLOAK_SERVICE}/realms/${KEYCLOAK_REALM}`;
|
|
21
23
|
console.log(`Keycloak PublicKey Url: ${realmUrl}`);
|
|
22
24
|
const resp = await axios.get(realmUrl);
|
|
23
25
|
const key = resp.data.public_key;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const KEYCLOAK_PUBLIC_KEY: any = await getKeycloakPublicKey();
|
|
26
|
+
KEYCLOAK_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
|
|
27
|
+
};
|
|
29
28
|
|
|
30
29
|
export const protect = (req: Request, res: Response, next: any) => {
|
|
31
30
|
const authHeader = req.headers["authorization"];
|