diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/JwtTokenUtils.kt b/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/JwtTokenUtils.kt index 68a02363d..987390eb5 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/JwtTokenUtils.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/JwtTokenUtils.kt @@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.auth.repository.util import com.x8bit.bitwarden.data.auth.repository.model.JwtTokenDataJson import com.x8bit.bitwarden.data.platform.datasource.network.util.base64UrlDecodeOrNull import kotlinx.serialization.json.Json +import timber.log.Timber /** * Internal, generally basic [Json] instance for JWT parsing purposes. @@ -17,17 +18,24 @@ private val json: Json by lazy { /** * Parses a [JwtTokenDataJson] from the given [jwtToken], or `null` if this parsing is not possible. */ -@Suppress("MagicNumber") +@Suppress("MagicNumber", "TooGenericExceptionCaught") fun parseJwtTokenDataOrNull(jwtToken: String): JwtTokenDataJson? { val parts = jwtToken.split(".") - if (parts.size != 3) return null + if (parts.size != 3) { + Timber.e(IllegalArgumentException("Incorrect number of parts"), "Invalid JWT Token") + return null + } val dataJson = parts[1] - val decodedDataJson = dataJson.base64UrlDecodeOrNull() ?: return null + val decodedDataJson = dataJson.base64UrlDecodeOrNull() ?: run { + Timber.e(IllegalArgumentException("Unable to decode"), "Invalid JWT Token") + return null + } return try { json.decodeFromString(decodedDataJson) - } catch (_: Throwable) { + } catch (throwable: Throwable) { + Timber.e(throwable, "Failed to decode JwtTokenDataJson") null } }