From 076cf372ced245a1e3412275839a11aaca8aa2da Mon Sep 17 00:00:00 2001 From: Yathindra Date: Thu, 21 Apr 2022 14:56:08 +0530 Subject: [PATCH 1/4] Handle nbf claim rejection error --- lib/src/helpers/crypto-helper.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/src/helpers/crypto-helper.ts b/lib/src/helpers/crypto-helper.ts index 2c82df2c..c69d9d07 100644 --- a/lib/src/helpers/crypto-helper.ts +++ b/lib/src/helpers/crypto-helper.ts @@ -113,6 +113,24 @@ export class CryptoHelper { "ID token validation returned false" ) ); + }).catch((error) => { + if(error?.code === "ERR_JWT_CLAIM_VALIDATION_FAILED" && error?.claim === "nbf") { + return Promise.reject( + new AsgardeoAuthException( + "JS-CRYPTO_UTILS-IVIT-IV02", + "JWT NBF CLAIM VALIDATION FAILED", + "JWT NBF claim validation has been failed" + ) + ); + } else { + return Promise.reject( + new AsgardeoAuthException( + "JS-CRYPTO_UTILS-IVIT-IV03", + "JWT VALIDATION FAILED", + "JWT validation has been failed" + ) + ); + } }); } From 6ecb91745cd5734cc49df57357df61595244402f Mon Sep 17 00:00:00 2001 From: Yathindra Date: Thu, 21 Apr 2022 15:40:41 +0530 Subject: [PATCH 2/4] move jwt error to constants --- lib/src/constants/data.ts | 3 +++ lib/src/helpers/crypto-helper.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/src/constants/data.ts b/lib/src/constants/data.ts index 1cb590b3..394ced9c 100644 --- a/lib/src/constants/data.ts +++ b/lib/src/constants/data.ts @@ -30,3 +30,6 @@ export const PKCE_SEPARATOR = "#"; export const SUPPORTED_SIGNATURE_ALGORITHMS = [ "RS256", "RS512", "RS384", "PS256" ]; + +export const JOSE_CLAIM_VALIDATION_ERROR = "ERR_JWT_CLAIM_VALIDATION_FAILED"; +export const JOSE_NBF_CLAIM = "nbf"; diff --git a/lib/src/helpers/crypto-helper.ts b/lib/src/helpers/crypto-helper.ts index c69d9d07..1a7c867e 100644 --- a/lib/src/helpers/crypto-helper.ts +++ b/lib/src/helpers/crypto-helper.ts @@ -16,7 +16,7 @@ * under the License. */ -import { SUPPORTED_SIGNATURE_ALGORITHMS } from "../constants"; +import { JOSE_CLAIM_VALIDATION_ERROR, JOSE_NBF_CLAIM, SUPPORTED_SIGNATURE_ALGORITHMS } from "../constants"; import { AsgardeoAuthException } from "../exception"; import { CryptoUtils, DecodedIDTokenPayload, JWKInterface } from "../models"; @@ -114,7 +114,7 @@ export class CryptoHelper { ) ); }).catch((error) => { - if(error?.code === "ERR_JWT_CLAIM_VALIDATION_FAILED" && error?.claim === "nbf") { + if(error?.code === JOSE_CLAIM_VALIDATION_ERROR && error?.claim === JOSE_NBF_CLAIM) { return Promise.reject( new AsgardeoAuthException( "JS-CRYPTO_UTILS-IVIT-IV02", From 5d93e1ca6653587a1b76c732ff5d5f90571045d2 Mon Sep 17 00:00:00 2001 From: Yathindra Date: Thu, 21 Apr 2022 16:59:03 +0530 Subject: [PATCH 3/4] done source code improvements --- lib/src/constants/data.ts | 4 ++-- lib/src/helpers/crypto-helper.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/constants/data.ts b/lib/src/constants/data.ts index 394ced9c..f42f77b2 100644 --- a/lib/src/constants/data.ts +++ b/lib/src/constants/data.ts @@ -31,5 +31,5 @@ export const SUPPORTED_SIGNATURE_ALGORITHMS = [ "RS256", "RS512", "RS384", "PS256" ]; -export const JOSE_CLAIM_VALIDATION_ERROR = "ERR_JWT_CLAIM_VALIDATION_FAILED"; -export const JOSE_NBF_CLAIM = "nbf"; +export const JOSE_CLAIM_VALIDATION_ERROR: string = "ERR_JWT_CLAIM_VALIDATION_FAILED"; +export const JOSE_NBF_CLAIM: string= "nbf"; diff --git a/lib/src/helpers/crypto-helper.ts b/lib/src/helpers/crypto-helper.ts index 1a7c867e..f9f8fbf8 100644 --- a/lib/src/helpers/crypto-helper.ts +++ b/lib/src/helpers/crypto-helper.ts @@ -122,15 +122,15 @@ export class CryptoHelper { "JWT NBF claim validation has been failed" ) ); - } else { - return Promise.reject( - new AsgardeoAuthException( - "JS-CRYPTO_UTILS-IVIT-IV03", - "JWT VALIDATION FAILED", - "JWT validation has been failed" - ) - ); } + + return Promise.reject( + new AsgardeoAuthException( + "JS-CRYPTO_UTILS-IVIT-IV03", + "JWT VALIDATION FAILED", + "JWT validation has been failed" + ) + ); }); } From 23322484d922d8469f139e0f41c2efc71b7bc9b2 Mon Sep 17 00:00:00 2001 From: Yathindra Date: Thu, 21 Apr 2022 17:03:26 +0530 Subject: [PATCH 4/4] improve typo --- lib/src/constants/data.ts | 4 ++-- lib/src/helpers/crypto-helper.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/constants/data.ts b/lib/src/constants/data.ts index f42f77b2..e579146b 100644 --- a/lib/src/constants/data.ts +++ b/lib/src/constants/data.ts @@ -31,5 +31,5 @@ export const SUPPORTED_SIGNATURE_ALGORITHMS = [ "RS256", "RS512", "RS384", "PS256" ]; -export const JOSE_CLAIM_VALIDATION_ERROR: string = "ERR_JWT_CLAIM_VALIDATION_FAILED"; -export const JOSE_NBF_CLAIM: string= "nbf"; +export const CLAIM_VALIDATION_ERROR: string = "ERR_JWT_CLAIM_VALIDATION_FAILED"; +export const NBF_CLAIM: string= "nbf"; diff --git a/lib/src/helpers/crypto-helper.ts b/lib/src/helpers/crypto-helper.ts index f9f8fbf8..0bc66790 100644 --- a/lib/src/helpers/crypto-helper.ts +++ b/lib/src/helpers/crypto-helper.ts @@ -16,7 +16,7 @@ * under the License. */ -import { JOSE_CLAIM_VALIDATION_ERROR, JOSE_NBF_CLAIM, SUPPORTED_SIGNATURE_ALGORITHMS } from "../constants"; +import { CLAIM_VALIDATION_ERROR, NBF_CLAIM, SUPPORTED_SIGNATURE_ALGORITHMS } from "../constants"; import { AsgardeoAuthException } from "../exception"; import { CryptoUtils, DecodedIDTokenPayload, JWKInterface } from "../models"; @@ -114,7 +114,7 @@ export class CryptoHelper { ) ); }).catch((error) => { - if(error?.code === JOSE_CLAIM_VALIDATION_ERROR && error?.claim === JOSE_NBF_CLAIM) { + if(error?.code === CLAIM_VALIDATION_ERROR && error?.claim === NBF_CLAIM) { return Promise.reject( new AsgardeoAuthException( "JS-CRYPTO_UTILS-IVIT-IV02", @@ -123,7 +123,7 @@ export class CryptoHelper { ) ); } - + return Promise.reject( new AsgardeoAuthException( "JS-CRYPTO_UTILS-IVIT-IV03",