From 7cf7dd591089f386e69678178758eb577cbd8406 Mon Sep 17 00:00:00 2001 From: Jan Kobersky <5406945+kober32@users.noreply.github.com> Date: Fri, 22 Dec 2023 11:16:00 +0100 Subject: [PATCH] Added exception handling in PAC deeplink parsing (#127) --- .../android/mtokensdk/operation/PACUtils.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt b/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt index 75db36a..186a159 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt @@ -44,18 +44,23 @@ class PACUtils { /** Method accepts deeplink Uri and returns payload data or null */ fun parseDeeplink(uri: Uri): PACData? { - // Deeplink can have two query items with operationId & optional totp or single query item with JWT value - uri.getQueryParameter("oid")?.let { operationId -> - if (uri.query?.contains(operationId) == false) { - Logger.e("Operation could not be resolved - probably contains invalid characters - please, encode the URL first") + try { + // Deeplink can have two query items with operationId & optional totp or single query item with JWT value + uri.getQueryParameter("oid")?.let { operationId -> + if (uri.query?.contains(operationId) == false) { + Logger.e("Operation could not be resolved - probably contains invalid characters - please, encode the URL first") + return null + } + val totp = uri.getQueryParameter("totp") ?: uri.getQueryParameter("potp") + return PACData(operationId, totp) + } ?: uri.queryParameterNames.firstOrNull()?.let { + return parseJWT(uri.getQueryParameter(it) ?: "") + } ?: run { + Logger.e("Failed to parse deeplink. Valid keys not found in Uri: $uri") return null } - val totp = uri.getQueryParameter("totp") ?: uri.getQueryParameter("potp") - return PACData(operationId, totp) - } ?: uri.queryParameterNames.firstOrNull()?.let { - return parseJWT(uri.getQueryParameter(it) ?: "") - } ?: run { - Logger.e("Failed to parse deeplink. Valid keys not found in Uri: $uri") + } catch (t: Throwable) { + Logger.e("Failed to parse deeplink - $t") return null } }