Skip to content

Commit c6300ae

Browse files
authored
Merge pull request #308 from adamint/dev/306-invalid-android-verifier
only set pkce verifier on android pkce activity launch
2 parents 6694c46 + 147af8e commit c6300ae

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/androidMain/kotlin/com/adamratzman/spotify/auth/SpotifyDefaultCredentialStore.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public class SpotifyDefaultCredentialStore(
5353
*/
5454
public const val SpotifyRefreshTokenKey: String = "spotifyRefreshToken"
5555

56+
/**
57+
* The PKCE code verifier key currently being used in [EncryptedSharedPreferences]
58+
*/
59+
public const val SpotifyCurrentPkceCodeVerifierKey: String = "spotifyCurrentPkceCodeVerifier"
60+
5661
/**
5762
* The activity to return to if re-authentication is necessary on implicit authentication. Null except during authentication when using [guardValidImplicitSpotifyApi]
5863
*/
@@ -101,6 +106,13 @@ public class SpotifyDefaultCredentialStore(
101106
get() = encryptedPreferences.getString(SpotifyRefreshTokenKey, null)
102107
set(value) = encryptedPreferences.edit().putString(SpotifyRefreshTokenKey, value).apply()
103108

109+
/**
110+
* Get/set the current Spotify PKCE code verifier.
111+
*/
112+
public var currentSpotifyPkceCodeVerifier: String?
113+
get() = encryptedPreferences.getString(SpotifyCurrentPkceCodeVerifierKey, null)
114+
set(value) = encryptedPreferences.edit().putString(SpotifyCurrentPkceCodeVerifierKey, value).apply()
115+
104116
/**
105117
* Get/set the Spotify [Token] obtained from [spotifyToken].
106118
* If the token has expired according to [spotifyTokenExpiresAt], this will return null.

src/androidMain/kotlin/com/adamratzman/spotify/auth/pkce/AbstractSpotifyPkceLoginActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public abstract class AbstractSpotifyPkceLoginActivity : AppCompatActivity() {
9292
// launch the activity when a Spotify intent result has been received
9393
if (intent?.isSpotifyPkceAuthIntent(redirectUri) == false) {
9494
authorizationIntent = Intent(Intent.ACTION_VIEW, getAuthorizationUrl())
95+
credentialStore.currentSpotifyPkceCodeVerifier = pkceCodeVerifier
9596
startActivity(authorizationIntent)
9697
finish()
9798
}
@@ -150,7 +151,7 @@ public abstract class AbstractSpotifyPkceLoginActivity : AppCompatActivity() {
150151
redirectUri = redirectUri,
151152
authorization = SpotifyUserAuthorization(
152153
authorizationCode = authorizationCode,
153-
pkceCodeVerifier = pkceCodeVerifier
154+
pkceCodeVerifier = credentialStore.currentSpotifyPkceCodeVerifier
154155
),
155156
options ?: {}
156157
).build()

0 commit comments

Comments
 (0)