@cemiar/auth-sdk 1.0.6 → 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.
|
@@ -35,7 +35,7 @@ function createSigningKeyResolver(jwksUri, cacheMaxAgeMs) {
|
|
|
35
35
|
}
|
|
36
36
|
export async function registerCemiarAuthHapi(server, options) {
|
|
37
37
|
var _a;
|
|
38
|
-
const { authUrl, strategyName = "cemiar-jwt", algorithms = DEFAULT_ALGORITHMS, cacheMaxAgeMs = DEFAULT_CACHE_MAX_AGE, validate = defaultValidate } = options;
|
|
38
|
+
const { authUrl, auds, strategyName = "cemiar-jwt", algorithms = DEFAULT_ALGORITHMS, cacheMaxAgeMs = DEFAULT_CACHE_MAX_AGE, validate = defaultValidate } = options;
|
|
39
39
|
const jwksUri = `${normalizeBaseUrl(authUrl)}/.well-known/jwks.json`;
|
|
40
40
|
const { getKey } = createSigningKeyResolver(jwksUri, cacheMaxAgeMs);
|
|
41
41
|
const pluginModule = await import("hapi-auth-jwt2");
|
|
@@ -47,6 +47,13 @@ export async function registerCemiarAuthHapi(server, options) {
|
|
|
47
47
|
return { key };
|
|
48
48
|
},
|
|
49
49
|
validate: async (decoded, request, h) => {
|
|
50
|
+
const payload = decoded.payload;
|
|
51
|
+
const tokenAud = payload === null || payload === void 0 ? void 0 : payload.aud;
|
|
52
|
+
const tokenAuds = Array.isArray(tokenAud) ? tokenAud : tokenAud ? [tokenAud] : [];
|
|
53
|
+
const hasValidAud = tokenAuds.length > 0 && tokenAuds.every(aud => auds.includes(aud));
|
|
54
|
+
if (!hasValidAud) {
|
|
55
|
+
return { isValid: false };
|
|
56
|
+
}
|
|
50
57
|
return validate(decoded, request, h);
|
|
51
58
|
},
|
|
52
59
|
verifyOptions: {
|
package/dist/shared/Types.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export interface JwtValidateResult {
|
|
|
68
68
|
export type JwtValidateFn = (decoded: JwtParts, request: Request, h: ResponseToolkit) => Promise<JwtValidateResult> | JwtValidateResult;
|
|
69
69
|
export interface HapiJwtStrategyOptions {
|
|
70
70
|
authUrl: string;
|
|
71
|
+
auds: string[];
|
|
71
72
|
strategyName?: string;
|
|
72
73
|
algorithms?: string[];
|
|
73
74
|
cacheMaxAgeMs?: number;
|