michaelv
10/22/2024, 12:57 AMAleksei Tirman [JB]
10/22/2024, 5:54 AMmichaelv
10/22/2024, 7:12 AMAleksei Tirman [JB]
10/25/2024, 11:17 AMAuthorization
header, which isn't allowed to be managed directly.michaelv
10/26/2024, 2:17 AMmichaelv
10/26/2024, 2:18 AMmichaelv
10/26/2024, 2:18 AMmichaelv
10/26/2024, 2:19 AMAleksei Tirman [JB]
10/26/2024, 10:47 AMAuthorization
header can be sent through the Fetch API. Can you describe the exact problem which occurs while using the Auth
plugin?michaelv
10/26/2024, 11:47 PMinstall(Auth) {
bearer {
loadTokens {
// Load tokens from a local storage and return them as the 'BearerTokens' instance
BearerTokens("abc123", "xyz111")
}
}
}
The call looks like this:
val response: HttpResponse = client.get("https://<API>") {
// header("Authorization", "Bearer $accessToken")
}
If I set the bearer using the Auth plugin as above I can comment/remove the Authorization header line and it will work on ios and android but for WASM I will get a 401. If I keep this line then WASM works fine too.
The bigger problem though is that I can’t take advantage of the refresh tokens block and I have to manually handle refreshing for every API call which adds a lot of complexity.
install(Auth) {
bearer {
// Load tokens ...
refreshTokens { // this: RefreshTokensParams
// Refresh tokens and return them as the 'BearerTokens' instance
BearerTokens("def456", "xyz111")
}
}
}
michaelv
10/27/2024, 12:03 AM// Get bodyAsText and manual decodeFromString since deserialization doesn't seem to work properly yet on WASM
val responseBody = response.bodyAsText()
val someObject = Json.decodeFromString<SomeObject>(responseBody)
// this doesn't currently work on WASM
// val someObject: SomeObject = response.body()
Again it works fine on ios and android if I use that last line instead but on WASM I get this error:
An unexpected error occurred: NoTransformationFoundException: Expected response body of the type ‘class SomeObject’ but was ‘class SourceByteReadChannel’Aleksei Tirman [JB]
10/29/2024, 2:37 PMGlobalScope.launch {
val client = HttpClient {
install(Auth) {
bearer {
loadTokens {
BearerTokens("", "")
}
refreshTokens {
println("Refreshing...")
BearerTokens("token", "token")
}
}
}
}
val response = client.get("<https://httpbin.org/bearer>")
println(response.bodyAsText())
}
You can find a sample project attached.michaelv
10/31/2024, 8:12 AMmichaelv
10/31/2024, 8:20 AMmichaelv
10/31/2024, 8:21 AMmichaelv
10/31/2024, 8:22 AMmichaelv
10/31/2024, 8:29 AMmichaelv
10/31/2024, 8:30 AMmichaelv
10/31/2024, 8:31 AMmichaelv
11/01/2024, 1:03 AMAleksei Tirman [JB]
11/01/2024, 7:43 AMor at least maybe the Js engine doesn’t support WASM yet but CIO doesThe CIO engine doesn't support the WASM target.
Maybe the configuration is handled automatically now so we don’t need to configure it for each platform?Yes. If there are respective dependencies in place and the engine isn't passed to the
HttpClient
constructor, the engine will be resolved automatically based on the platform.