@@ -20,9 +20,8 @@ import com.amplifyframework.auth.exceptions.UnknownException
2020import com.amplifyframework.statemachine.util.mask
2121import java.time.Instant
2222import kotlin.text.Charsets.UTF_8
23- import kotlinx.serialization.Serializable
24- import org.json.JSONObject
2523import kotlinx.serialization.KSerializer
24+ import kotlinx.serialization.Serializable
2625import kotlinx.serialization.SerializationException
2726import kotlinx.serialization.builtins.serializer
2827import kotlinx.serialization.encoding.Decoder
@@ -31,6 +30,7 @@ import kotlinx.serialization.json.JsonDecoder
3130import kotlinx.serialization.json.JsonObject
3231import kotlinx.serialization.json.JsonPrimitive
3332import kotlinx.serialization.json.jsonPrimitive
33+ import org.json.JSONObject
3434
3535internal abstract class Jwt {
3636 abstract val tokenValue: String
@@ -155,17 +155,15 @@ internal data class CognitoUserPoolTokens(
155155/* *
156156 * Helper function to extract token value from either flat or nested format
157157 */
158- private fun extractTokenValue (decoder : Decoder , tokenType : String ): String {
159- return if (decoder is JsonDecoder ) {
160- when (val element = decoder.decodeJsonElement()) {
161- is JsonPrimitive -> element.content // Flat format: "token": "value"
162- is JsonObject -> element[" tokenValue" ]?.jsonPrimitive?.content
163- ? : throw SerializationException (" Missing tokenValue in nested $tokenType " )
164- else -> throw SerializationException (" Expected string or object for $tokenType " )
165- }
166- } else {
167- decoder.decodeString() // Fallback for non-JSON decoders
158+ private fun extractTokenValue (decoder : Decoder , tokenType : String ): String = if (decoder is JsonDecoder ) {
159+ when (val element = decoder.decodeJsonElement()) {
160+ is JsonPrimitive -> element.content // Flat format: "token": "value"
161+ is JsonObject -> element[" tokenValue" ]?.jsonPrimitive?.content
162+ ? : throw SerializationException (" Missing tokenValue in nested $tokenType " )
163+ else -> throw SerializationException (" Expected string or object for $tokenType " )
168164 }
165+ } else {
166+ decoder.decodeString() // Fallback for non-JSON decoders
169167}
170168
171169/* *
@@ -193,4 +191,4 @@ internal object RefreshTokenAsStringSerializer : KSerializer<RefreshToken> {
193191 override val descriptor = String .serializer().descriptor
194192 override fun serialize (encoder : Encoder , value : RefreshToken ) = encoder.encodeString(value.tokenValue)
195193 override fun deserialize (decoder : Decoder ) = RefreshToken (extractTokenValue(decoder, " RefreshToken" ))
196- }
194+ }
0 commit comments