Closed rsicarelli closed 2 years ago
Thank you for the detailed bug report. Instead of a new code verifier being created on activity creation, it should live in the credential provider and be reset when the activity is to be started. @rsicarelli would you be able to confirm this cannot be reproduced after the next minor version releases tomorrow? I will comment here then.
@adamint sure thing, let me know once its available!
@rsicarelli 3.8.6 is available (syncing)
@adamint good job, the fix works! Many thanks for your support
Wonderful, glad to hear it. I’ll close the issue now
Description
I'm trying to use the PKCE flow on Android and I'm getting the following error:
Apparently, the reason is that the
AbstractSpotifyPkceLoginActivity:pkceCodeVerifier
attribute gets recreated after redirecting from the opened URL from the device browser.To reproduce
AbstractSpotifyPkceLoginActivity
pkceCodeVerifier
isGxo3to4KqcxPSN9udvacLxrq3xWmyrohY5yIMhHrFhqhMKmopFefepux9nZ1M2cXwbCUHaDnndSb2ZUtwq4POGmADh2RMlyeu
AbstractSpotifyPkceLoginActivity
is created. Now, thepkceCodeVerifier
code iseBId4eXjoWrRrY6xdJCTDHe9ETcorXqLEWU4rKbdyTIqzDUNNskTHcS5awd2dH4UPDcyWPHodnbi1teNdo8U68dYDsNqBDGRv
handleSpotifyAuthenticationResponse
is called with the response. No errorspkceCodeVerifier
is different than the original request on step 3, now using the one created on step 6Click to expand
``` com.adamratzman.spotify.SpotifyException$AuthenticationException: Invalid credentials provided in the login process (clientId=..., clientSecret=null, authCode=....) 2022-03-14 15:53:50.165 W/System.err: at com.adamratzman.spotify.SpotifyClientApiBuilder.build(SpotifyApiBuilder.kt:962) 2022-03-14 15:53:50.165 W/System.err: at com.adamratzman.spotify.SpotifyClientApiBuilder$build$1.invokeSuspend(Unknown Source:15) 2022-03-14 15:53:50.165 W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 2022-03-14 15:53:50.165 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:191) 2022-03-14 15:53:50.165 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:147) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:93) 2022-03-14 15:53:50.166 W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:191) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:147) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:93) 2022-03-14 15:53:50.166 W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:191) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:147) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:93) 2022-03-14 15:53:50.166 W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:191) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:147) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15) 2022-03-14 15:53:50.166 W/System.err: at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:93) 2022-03-14 15:53:50.166 W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:279) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38) 2022-03-14 15:53:50.166 W/System.err: at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1) 2022-03-14 15:53:50.166 W/System.err: at com.adamratzman.spotify.auth.pkce.AbstractSpotifyPkceLoginActivity.onResume(AbstractSpotifyPkceLoginActivity.kt:106) 2022-03-14 15:53:50.166 W/System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1571) 2022-03-14 15:53:50.166 W/System.err: at android.app.Activity.performResume(Activity.java:8141) 2022-03-14 15:53:50.166 W/System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4626) 2022-03-14 15:53:50.166 W/System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4668) 2022-03-14 15:53:50.166 W/System.err: at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 2022-03-14 15:53:50.166 W/System.err: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 2022-03-14 15:53:50.166 W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 2022-03-14 15:53:50.166 W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251) 2022-03-14 15:53:50.166 W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106) 2022-03-14 15:53:50.166 W/System.err: at android.os.Looper.loop(Looper.java:233) 2022-03-14 15:53:50.166 W/System.err: at android.app.ActivityThread.main(ActivityThread.java:8068) 2022-03-14 15:53:50.166 W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2022-03-14 15:53:50.166 W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631) 2022-03-14 15:53:50.166 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978) 2022-03-14 15:53:50.167 W/System.err: Caused by: com.adamratzman.spotify.SpotifyException$ParseException: Unable to parse {"error":"invalid_grant","error_description":"code_verifier was incorrect"} (Fields [access_token, token_type, expires_in] are required for type with serial name 'com.adamratzman.spotify.models.Token', but they were missing) 2022-03-14 15:53:50.167 W/System.err: at com.adamratzman.spotify.models.serialization.SerializationUtilsKt.parseJson(SerializationUtils.kt:33) 2022-03-14 15:53:50.167 W/System.err: at com.adamratzman.spotify.models.serialization.SerializationUtilsKt.toObject(SerializationUtils.kt:41) 2022-03-14 15:53:50.167 W/System.err: at com.adamratzman.spotify.SpotifyClientApiBuilder.build(SpotifyApiBuilder.kt:952) 2022-03-14 15:53:50.167 W/System.err: ... 44 more 2022-03-14 15:53:50.167 W/System.err: Caused by: kotlinx.serialization.MissingFieldException: Fields [access_token, token_type, expires_in] are required for type with serial name 'com.adamratzman.spotify.models.Token', but they were missing 2022-03-14 15:53:50.167 W/System.err: at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20) 2022-03-14 15:53:50.167 W/System.err: at com.adamratzman.spotify.models.Token.Workaround
Overriding the variable
pkceCodeVerifier
on my Activity, setting to a fixed string works as expected:Expected behavior For what I understood, the
pkceCodeVerifier
attribute must be preserved/saved after user gets back to the app.Project configuration
Smartphone:
Additional info
singleInstance
and I got the same error. Also tried to remove thelaunchMode
at all, and still the same error