mirror of
https://github.com/mihonapp/mihon.git
synced 2025-01-27 10:24:55 +01:00
ref: added more specificity and removed unnecessary code in Hikka Api
This commit is contained in:
parent
f39e947ece
commit
41db4a5865
@ -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>()
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user