From abe85c00dcb7484edd30effb0f936f85dfcfd492 Mon Sep 17 00:00:00 2001 From: "Josep Milan K.A" Date: Mon, 4 Nov 2024 13:39:31 +0530 Subject: [PATCH] Fix: Trim double quotes from disclosures --- .../models/WrappedVpTokenResponse.kt | 1 + .../services/sdjwt/SDJWTService.kt | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/WrappedVpTokenResponse.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/WrappedVpTokenResponse.kt index 3e2ca67..c18a0ae 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/WrappedVpTokenResponse.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/WrappedVpTokenResponse.kt @@ -2,6 +2,7 @@ package com.ewc.eudi_wallet_oidc_android.models import com.google.gson.annotations.SerializedName data class VPTokenResponse( @SerializedName("location") var location: String? = null, + @SerializedName("redirect_uri") var redirectUri: String? = null ) data class WrappedVpTokenResponse( diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/sdjwt/SDJWTService.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/sdjwt/SDJWTService.kt index 66a8ac3..6036749 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/sdjwt/SDJWTService.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/sdjwt/SDJWTService.kt @@ -295,19 +295,25 @@ class SDJWTService : SDJWTServiceInterface { disclosures[index], Base64.URL_SAFE ).toString(charset("UTF-8")) - // Extract key-value pair from the encodedString val (decodedKey, decodedValue) = extractKeyValue(disclosure) - // Add key-value pair to jsonObject - // Check if decodedValue is an object + // Convert decodedValue to string first + val decodedValueStr = decodedValue.toString() + + // Check if the string has extra quotes and trim + val trimmedValue = if (decodedValueStr.startsWith("\"") && decodedValueStr.endsWith("\"")) { + decodedValueStr.trim('"') + } else { + decodedValueStr // Keep it as is if no extra quotes + } if (decodedValue is JsonObject) { // If it's an object, add it directly jsonObject.add(decodedKey, decodedValue) } else if (decodedValue is JsonArray) { - // If it's an object, add it directly + // If it's an array, add it directly jsonObject.add(decodedKey, decodedValue) } else { // Otherwise, add it as a property - jsonObject.addProperty(decodedKey, decodedValue.toString()) + jsonObject.addProperty(decodedKey, trimmedValue) } } catch (e: IllegalArgumentException) { // Handle invalid base64-encoded strings