@lucaapp/service-utils 4.7.0 → 4.9.0
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.
|
@@ -38,7 +38,7 @@ declare class ServiceIdentity {
|
|
|
38
38
|
}>;
|
|
39
39
|
getIdentityJWKS: () => Promise<JWKS>;
|
|
40
40
|
requireServiceIdentity: (service: string) => RequestHandler;
|
|
41
|
-
requireServiceIdentityV3: (
|
|
41
|
+
requireServiceIdentityV3: (...services: string[]) => import("../api/types/middleware").Middleware<never[], undefined, undefined, undefined, z.ZodObject<{
|
|
42
42
|
'x-identity': z.ZodEffects<z.ZodString, string, string>;
|
|
43
43
|
}, "strip", z.ZodTypeAny, {
|
|
44
44
|
'x-identity': string;
|
|
@@ -142,7 +142,7 @@ class ServiceIdentity {
|
|
|
142
142
|
request.body = payload.data;
|
|
143
143
|
next();
|
|
144
144
|
};
|
|
145
|
-
this.requireServiceIdentityV3 = (
|
|
145
|
+
this.requireServiceIdentityV3 = (...services) => (0, api_1.createMiddleware)({
|
|
146
146
|
schemas: {
|
|
147
147
|
headers: zod_1.z.object({
|
|
148
148
|
'x-identity': zod_1.z.string().refine(value => validator_1.default.isJWT(value)),
|
|
@@ -161,9 +161,19 @@ class ServiceIdentity {
|
|
|
161
161
|
if (typeof jwt !== 'string') {
|
|
162
162
|
throw new ServiceIdentityError(ServiceIdentityErrorType.NO_JWT_PROVIDED);
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
let payload = null;
|
|
165
|
+
for (const service of services) {
|
|
166
|
+
try {
|
|
167
|
+
const response = await jose.jwtVerify(jwt, this.getRemoteJWKS(service), this.getJwtVerifyOptions(service));
|
|
168
|
+
payload = response.payload;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (request.originalUrl !== payload?.url) {
|
|
176
|
+
throw new ServiceIdentityError(ServiceIdentityErrorType.URL_MISMATCH, `${originalUrl} !== ${payload?.url}`);
|
|
167
177
|
}
|
|
168
178
|
if (method !== payload.method) {
|
|
169
179
|
throw new ServiceIdentityError(ServiceIdentityErrorType.METHOD_MISMATCH, `${method} !== ${payload.method}`);
|