ref: added more specificity and removed unnecessary code in Hikka Api

This commit is contained in:
Lorg0n 2024-10-17 22:46:26 +03:00
parent f39e947ece
commit 41db4a5865
2 changed files with 3 additions and 9 deletions

View File

@ -48,15 +48,10 @@ class HikkaApi(
}
}
suspend fun getTokenInfo(accessToken: String): HKAuthTokenInfo {
private suspend fun getTokenInfo(accessToken: String): HKAuthTokenInfo {
return withIOContext {
val request = Request.Builder()
.url("${BASE_API_URL}/auth/token/info")
.header("auth", accessToken)
.get()
.build()
with(json) {
client.newCall(request)
client.newCall(authTokenInfo(accessToken))
.awaitSuccess()
.parseAs<HKAuthTokenInfo>()
}

View File

@ -8,14 +8,13 @@ import okhttp3.Response
import uy.kohesive.injekt.injectLazy
class HikkaInterceptor(private val hikka: Hikka) : Interceptor {
private val json: Json by injectLazy()
private var oauth: HKOAuth? = hikka.loadOAuth()
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
val currAuth = oauth ?: throw Exception("Not authenticated with Hikka")
val currAuth = oauth ?: throw Exception("Hikka: You are not authorized")
if (currAuth.isExpired()) {
val refreshTokenResponse = chain.proceed(HikkaApi.refreshTokenRequest(currAuth.accessToken))