Skip to content

Commit 7b1477d

Browse files
committed
fix infinite loop in token refresh
1 parent 64da749 commit 7b1477d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyApi.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import com.adamratzman.spotify.models.SpotifyAuthenticationException
2626
import com.adamratzman.spotify.models.Token
2727
import com.adamratzman.spotify.models.TokenValidityResponse
2828
import com.adamratzman.spotify.models.serialization.toObject
29-
import com.adamratzman.spotify.utils.getCurrentTimeMs
3029
import com.adamratzman.spotify.utils.toList
3130

3231
internal const val base = "https://api.spotify.com/v1"
@@ -70,7 +69,7 @@ abstract class SpotifyApi internal constructor(
7069
field = value
7170
}
7271
val logger = SpotifyLogger(enableLogger)
73-
val expireTime: Long get() = getCurrentTimeMs() + token.expiresIn * 1000
72+
val expireTime: Long get() = token.expiresAt
7473
var runExecutableFunctions = true
7574

7675
abstract val search: SearchApi

src/commonMain/kotlin/com.adamratzman.spotify/http/HttpConnection.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class HttpConnection constructor(
135135
api != null && api.automaticRefresh
136136
) {
137137
api.refreshToken()
138-
return@runBlocking execute(additionalHeaders)
138+
val newAdditionalHeaders = additionalHeaders?.toMutableList() ?: mutableListOf()
139+
newAdditionalHeaders.add(0, HttpHeader("Authorization", "Bearer ${api.token.accessToken}"))
140+
return@runBlocking execute(newAdditionalHeaders, retryIf502)
139141
}
140142

141143
return@runBlocking HttpResponse(

0 commit comments

Comments
 (0)