response-standardizer 1.0.7 → 1.0.8
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.js +2 -1
- package/package.json +1 -1
- package/src/index.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export const initKeycloak = async (config) => {
|
|
|
7
7
|
const KEYCLOAK_SERVICE = config.service ?? "localhost";
|
|
8
8
|
const KEYCLOAK_REALM = config.realm ?? "master";
|
|
9
9
|
const realmUrl = `http://${KEYCLOAK_SERVICE}/realms/${KEYCLOAK_REALM}`;
|
|
10
|
-
|
|
10
|
+
info(`Keycloak PublicKey Url: ${realmUrl}`);
|
|
11
11
|
const resp = await axios.get(realmUrl);
|
|
12
12
|
const key = resp.data.public_key;
|
|
13
13
|
KEYCLOAK_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
|
|
@@ -23,6 +23,7 @@ export const protect = (allowedRoles) => {
|
|
|
23
23
|
try {
|
|
24
24
|
const decoded = jwt.verify(token, KEYCLOAK_PUBLIC_KEY, { algorithms: ["RS256"] });
|
|
25
25
|
req.user = decoded;
|
|
26
|
+
req.token = token;
|
|
26
27
|
if (allowedRoles)
|
|
27
28
|
return role(req, res, next, allowedRoles);
|
|
28
29
|
next();
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const initKeycloak = async (config: { service?: string; realm?: string })
|
|
|
21
21
|
const KEYCLOAK_SERVICE = config.service ?? "localhost";
|
|
22
22
|
const KEYCLOAK_REALM = config.realm ?? "master";
|
|
23
23
|
const realmUrl = `http://${KEYCLOAK_SERVICE}/realms/${KEYCLOAK_REALM}`;
|
|
24
|
-
|
|
24
|
+
info(`Keycloak PublicKey Url: ${realmUrl}`);
|
|
25
25
|
const resp = await axios.get(realmUrl);
|
|
26
26
|
const key = resp.data.public_key;
|
|
27
27
|
KEYCLOAK_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
|
|
@@ -40,6 +40,7 @@ export const protect = (allowedRoles?: string[]) => {
|
|
|
40
40
|
try {
|
|
41
41
|
const decoded = jwt.verify(token, KEYCLOAK_PUBLIC_KEY, { algorithms: ["RS256"] });
|
|
42
42
|
(req as any).user = decoded;
|
|
43
|
+
(req as any).token = token;
|
|
43
44
|
if(allowedRoles)
|
|
44
45
|
return role(req, res, next, allowedRoles);
|
|
45
46
|
|