JWTDecode.Android icon indicating copy to clipboard operation
JWTDecode.Android copied to clipboard

Kotlin Multiplatform Implementation

Open blackwiz4rd opened this issue 1 year ago • 0 comments

Checklist

  • [X] I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • [X] I have looked into the API documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Hello all, this library currently won't work with kotlin multiplatform module because it's using the:

  • https://developer.android.com/reference/android/util/Base64
  • https://developer.android.com/reference/android/os/Parcelable It would be nice to replace this function with ktor's utility function:
  • https://api.ktor.io/ktor-utils/io.ktor.util/decode-base64-bytes.html

Example implementation in my code (splitToken is copied from this project)

val jwtBody = JWTPayload.splitToken(loginData.access_token ?: "")?.get(1)
if (jwtBody.isNullOrEmpty()) {
    throw IllegalArgumentException()
}
val jwtAccessToken = Json{ ignoreUnknownKeys = true }.decodeFromString<JWTPayload>(
    jwtBody.decodeBase64Bytes().decodeToString()
)
if (jwtAccessToken.sub.isEmpty()) {
    throw IllegalArgumentException()
}

Regards, Luca.

Describe the ideal solution

Replace base64 and parcelable function/object.

Alternatives and current workarounds

Implement native code functions/libs.

Additional context

No response

blackwiz4rd avatar Jan 15 '24 15:01 blackwiz4rd