Skip to content

Commit 96cc131

Browse files
authored
Merge pull request #1023 from DimensionDev/bugfix/bsky_refresh_token
fix bluesky refresh token loop
2 parents c33aeef + 86bab43 commit 96cc131

File tree

1 file changed

+17
-5
lines changed
  • shared/src/commonMain/kotlin/dev/dimension/flare/data/network/bluesky

1 file changed

+17
-5
lines changed

shared/src/commonMain/kotlin/dev/dimension/flare/data/network/bluesky/BlueskyService.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ internal data class BlueskyService(
4646
access = accessToken
4747
refresh = refreshToken
4848
tokenRefreshed = onTokenRefreshed
49+
this.baseUrl = baseUrl
4950
}
5051
install(AtprotoProxyPlugin)
5152

@@ -83,6 +84,7 @@ private class AtprotoProxyPlugin {
8384
*/
8485
internal class XrpcAuthPlugin(
8586
private val json: Json,
87+
private val baseUrl: String,
8688
private val accessToken: String? = null,
8789
private val refreshToken: String? = null,
8890
private val onTokenRefreshed: ((accessToken: String, refreshToken: String) -> Unit)? = null,
@@ -92,6 +94,7 @@ internal class XrpcAuthPlugin(
9294
var access: String? = null,
9395
var refresh: String? = null,
9496
var tokenRefreshed: ((accessToken: String, refreshToken: String) -> Unit)? = null,
97+
var baseUrl: String? = null,
9598
)
9699

97100
companion object : HttpClientPlugin<Config, XrpcAuthPlugin> {
@@ -100,10 +103,11 @@ internal class XrpcAuthPlugin(
100103
override fun prepare(block: Config.() -> Unit): XrpcAuthPlugin {
101104
val config = Config().apply(block)
102105
return XrpcAuthPlugin(
103-
config.json,
104-
config.access,
105-
config.refresh,
106-
config.tokenRefreshed,
106+
json = config.json,
107+
accessToken = config.access,
108+
refreshToken = config.refresh,
109+
onTokenRefreshed = config.tokenRefreshed,
110+
baseUrl = config.baseUrl!!,
107111
)
108112
}
109113

@@ -129,8 +133,16 @@ internal class XrpcAuthPlugin(
129133
}
130134

131135
if (response.getOrNull()?.error == "ExpiredToken") {
136+
scope.attributes
132137
val refreshResponse =
133-
scope.post("/xrpc/com.atproto.server.refreshSession") {
138+
ktorClient {
139+
install(DefaultRequest) {
140+
val hostUrl = Url(plugin.baseUrl)
141+
url.protocol = hostUrl.protocol
142+
url.host = hostUrl.host
143+
url.port = hostUrl.port
144+
}
145+
}.post("/xrpc/com.atproto.server.refreshSession") {
134146
plugin.refreshToken?.let { bearerAuth(it) }
135147
}
136148
if (StatusCode.fromCode(refreshResponse.status.value) == StatusCode.Okay) {

0 commit comments

Comments
 (0)