Skip to content

Commit

Permalink
feat: authts#4 reduce eslint errors of restrict-plus-operands
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Aug 24, 2021
1 parent e6e0bbd commit c8973f6
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/utils/JoseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export class JoseUtil {
}
} else {
Log.error("JoseUtil.validateJwt: Unsupported key type", key && key.kty);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("Unsupported key type: " + key && key.kty);
throw new Error("Unsupported key type: " + (key ? String(key.kty) : "undefined"));
}

return JoseUtil._validateJwt(jwt, key, issuer, audience, clockSkew, now, timeInsensitive);
Expand All @@ -74,8 +73,7 @@ export class JoseUtil {
}
if (payload.iss !== issuer) {
Log.error("JoseUtil._validateJwt: Invalid issuer in token", payload.iss);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("Invalid issuer in token: " + payload.iss);
throw new Error("Invalid issuer in token: " + String(payload.iss));
}

if (!payload.aud) {
Expand All @@ -85,13 +83,11 @@ export class JoseUtil {
const validAudience = payload.aud === audience || (Array.isArray(payload.aud) && payload.aud.indexOf(audience) >= 0);
if (!validAudience) {
Log.error("JoseUtil._validateJwt: Invalid audience in token", payload.aud);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("Invalid audience in token: " + payload.aud);
throw new Error("Invalid audience in token: " + String(payload.aud));
}
if (payload.azp && payload.azp !== audience) {
Log.error("JoseUtil._validateJwt: Invalid azp in token", payload.azp);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("Invalid azp in token: " + payload.azp);
throw new Error("Invalid azp in token: " + String(payload.azp));
}

if (!timeInsensitive) {
Expand All @@ -104,14 +100,12 @@ export class JoseUtil {
}
if (lowerNow < payload.iat) {
Log.error("JoseUtil._validateJwt: iat is in the future", payload.iat);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("iat is in the future: " + payload.iat);
throw new Error("iat is in the future: " + String(payload.iat));
}

if (payload.nbf && lowerNow < payload.nbf) {
Log.error("JoseUtil._validateJwt: nbf is in the future", payload.nbf);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("nbf is in the future: " + payload.nbf);
throw new Error("nbf is in the future: " + String(payload.nbf));
}

if (!payload.exp) {
Expand All @@ -120,8 +114,7 @@ export class JoseUtil {
}
if (payload.exp < upperNow) {
Log.error("JoseUtil._validateJwt: exp is in the past", payload.exp);
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
throw new Error("exp is in the past:" + payload.exp);
throw new Error("exp is in the past: " + String(payload.exp));
}
}

Expand Down

0 comments on commit c8973f6

Please sign in to comment.