Skip to content

Commit 74d60c8

Browse files
committed
Fix deleting refresh_token on refresh
* Fixed overwriting the `refresh_token` on refresh * Runned ktlint
1 parent bdfe025 commit 74d60c8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/kotlin/com/adamratzman/spotify/main/SpotifyAPI.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ class SpotifyApiBuilder {
245245
}
246246

247247
abstract class SpotifyAPI internal constructor(
248-
val clientId: String, val clientSecret: String,
249-
var token: Token, var useCache: Boolean
248+
val clientId: String,
249+
val clientSecret: String,
250+
var token: Token,
251+
var useCache: Boolean
250252
) {
251253
internal var expireTime = System.currentTimeMillis() + token.expires_in * 1000
252254
internal val executor = Executors.newScheduledThreadPool(2)
@@ -378,10 +380,13 @@ class SpotifyClientAPI internal constructor(
378380
).execute(HttpHeader("Authorization", "Basic ${"$clientId:$clientSecret".byteEncode()}")).body,
379381
Token::class.java
380382
)
381-
if (tempToken == null) {
383+
if (tempToken?.access_token == null) {
382384
logger.logWarning("Spotify token refresh failed")
383385
} else {
384-
this.token = tempToken
386+
this.token = tempToken.copy(
387+
refresh_token = tempToken.refresh_token ?: this.token.refresh_token,
388+
scope = tempToken.scope ?: this.token.scope
389+
)
385390
logger.logInfo("Successfully refreshed the Spotify token")
386391
}
387392
}

0 commit comments

Comments
 (0)