Skip to content

Commit accc638

Browse files
authored
Merge branch 'dev' into kotlinx.serialization
2 parents cb7e003 + b800bce commit accc638

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
@@ -249,8 +249,10 @@ class SpotifyApiBuilder {
249249
}
250250

251251
abstract class SpotifyAPI internal constructor(
252-
val clientId: String, val clientSecret: String,
253-
var token: Token, var useCache: Boolean
252+
val clientId: String,
253+
val clientSecret: String,
254+
var token: Token,
255+
var useCache: Boolean
254256
) {
255257
internal var expireTime = System.currentTimeMillis() + token.expires_in * 1000
256258
internal val executor = Executors.newScheduledThreadPool(2)
@@ -386,10 +388,13 @@ class SpotifyClientAPI internal constructor(
386388
contentType = "application/x-www-form-urlencoded"
387389
).execute(HttpHeader("Authorization", "Basic ${"$clientId:$clientSecret".byteEncode()}")).body
388390
.toObjectNullable<Token>(null)
389-
if (tempToken == null) {
391+
if (tempToken?.access_token == null) {
390392
logger.logWarning("Spotify token refresh failed")
391393
} else {
392-
this.token = tempToken
394+
this.token = tempToken.copy(
395+
refresh_token = tempToken.refresh_token ?: this.token.refresh_token,
396+
scope = tempToken.scope ?: this.token.scope
397+
)
393398
logger.logInfo("Successfully refreshed the Spotify token")
394399
}
395400
}

0 commit comments

Comments
 (0)