Skip to content

Commit

Permalink
Added exception handling in PAC deeplink parsing (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 committed Dec 22, 2023
1 parent 486a771 commit 45c417b
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 45c417b

Please sign in to comment.