How to hadle JWT expiration in commonMain

Hi there,

We are using a common KMM module inside our new Multiplatform app, but we got stuck at authentication using Ktor Client.

At first, everything worked fine in Android using Base64 class from java.util, but once we tried to build the project for iOS, and macOS, the big trouble began. Since java.util is not available there, we need to find a way to decode the JWT token to read its payload, expiration date, etc.

I believe there might be a good way to handle JWT tokens when authenticating via Ktor client.

Probably an expect class or expect object that exposes the functions you need and each platform delegates everything to it.

Same goes for base64 encoding/decoding!

Thank you so much @lamba92 for your answer.

Using expect and actual was one of the things that came to my mind.
However, it only worked fine for Android, but things got stuck for iOS and macOS.
It seems like the Swift methods and classes that are needed to be used for Base64 decoding, cannot be used in a Kotlin module!

Maybe I’m wrong, but it just did not work for me.

1 Like

Hello, I’m wondering if/how you resolved this as I am about to do the same.

Thanks in advance