Skip to content

Commit 162b20a

Browse files
committed
allow direct modification of the access token
1 parent 8144114 commit 162b20a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ sealed class SpotifyApi<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>(
126126
suspendRefreshToken()
127127
}
128128

129+
/**
130+
* Change the current [Token]'s access token
131+
*/
132+
fun updateTokenWith(tokenString: String) {
133+
updateToken {
134+
accessToken = tokenString
135+
}
136+
}
137+
138+
/**
139+
* Modify the current [Token] via DSL
140+
*/
141+
fun updateToken(modifier: Token.() -> Unit) {
142+
modifier(token)
143+
}
144+
129145
/**
130146
* A list of all endpoints included in this api type
131147
*/

src/commonMain/kotlin/com.adamratzman.spotify/models/Authentication.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import kotlinx.serialization.Transient
2323
*/
2424
@Serializable
2525
data class Token(
26-
@SerialName("access_token") val accessToken: String,
26+
@SerialName("access_token") var accessToken: String,
2727
@SerialName("token_type") val tokenType: String,
28-
@SerialName("expires_in") val expiresIn: Int,
29-
@SerialName("refresh_token") val refreshToken: String? = null,
30-
@SerialName("scope") private val scopeString: String? = null
28+
@SerialName("expires_in") var expiresIn: Int,
29+
@SerialName("refresh_token") var refreshToken: String? = null,
30+
@SerialName("scope") private var scopeString: String? = null
3131
) {
3232
@Transient
33-
val expiresAt: Long = getCurrentTimeMs() + expiresIn * 1000
33+
var expiresAt: Long = getCurrentTimeMs() + expiresIn * 1000
3434
@Transient
3535
var scopes: List<SpotifyScope> = scopeString?.let { str ->
3636
str.split(" ").mapNotNull { scope -> SpotifyScope.values().find { it.uri.equals(scope, true) } }

0 commit comments

Comments
 (0)