From 3bc8434cea48a40cf32557385bed05abf8fb9245 Mon Sep 17 00:00:00 2001 From: nithyaganeshng Date: Fri, 9 Jul 2021 12:36:20 -0700 Subject: [PATCH] don't fail if pin is missing in idtokenhint during validation --- .../validators/OidcPresentationRequestValidator.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sdk/src/main/java/com/microsoft/did/sdk/credential/service/validators/OidcPresentationRequestValidator.kt b/sdk/src/main/java/com/microsoft/did/sdk/credential/service/validators/OidcPresentationRequestValidator.kt index 5e595075..ae8288c2 100644 --- a/sdk/src/main/java/com/microsoft/did/sdk/credential/service/validators/OidcPresentationRequestValidator.kt +++ b/sdk/src/main/java/com/microsoft/did/sdk/credential/service/validators/OidcPresentationRequestValidator.kt @@ -71,10 +71,13 @@ class OidcPresentationRequestValidator @Inject constructor(private val jwtValida if (!jwtValidator.verifySignature(jwsToken)) throw InvalidSignatureException("Signature is not valid on id token hint.") val json = Json.decodeFromString(JsonObject.serializer(), jwsToken.content()) - val pinObject = json["pin"] as? JsonObject ?: throw InvalidPinDetailsException("PIN details is missing in request.") - val length = (pinObject["length"] as? JsonPrimitive)?.content?.toInt() ?: throw InvalidPinDetailsException("PIN length is missing in request.") - val type = (pinObject["type"] as? JsonPrimitive)?.content ?: throw InvalidPinDetailsException("PIN type is missing in request.") - if (length < 1) throw InvalidPinDetailsException("PIN length is invalid in request.") - if (!(type == "numeric" || type == "text")) throw InvalidPinDetailsException("PIN type is invalid in request.") + val pinObject = json["pin"] as? JsonObject + if (pinObject != null) { + val length = (pinObject["length"] as? JsonPrimitive)?.content?.toInt() + ?: throw InvalidPinDetailsException("PIN length is missing in request.") + val type = (pinObject["type"] as? JsonPrimitive)?.content ?: throw InvalidPinDetailsException("PIN type is missing in request.") + if (length < 1) throw InvalidPinDetailsException("PIN length is invalid in request.") + if (!(type == "numeric" || type == "text")) throw InvalidPinDetailsException("PIN type is invalid in request.") + } } } \ No newline at end of file