mirror of
https://github.com/mihonapp/mihon.git
synced 2025-01-28 19:04: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 {
|
return withIOContext {
|
||||||
val request = Request.Builder()
|
|
||||||
.url("${BASE_API_URL}/auth/token/info")
|
|
||||||
.header("auth", accessToken)
|
|
||||||
.get()
|
|
||||||
.build()
|
|
||||||
with(json) {
|
with(json) {
|
||||||
client.newCall(request)
|
client.newCall(authTokenInfo(accessToken))
|
||||||
.awaitSuccess()
|
.awaitSuccess()
|
||||||
.parseAs<HKAuthTokenInfo>()
|
.parseAs<HKAuthTokenInfo>()
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,13 @@ import okhttp3.Response
|
|||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class HikkaInterceptor(private val hikka: Hikka) : Interceptor {
|
class HikkaInterceptor(private val hikka: Hikka) : Interceptor {
|
||||||
|
|
||||||
private val json: Json by injectLazy()
|
private val json: Json by injectLazy()
|
||||||
private var oauth: HKOAuth? = hikka.loadOAuth()
|
private var oauth: HKOAuth? = hikka.loadOAuth()
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val originalRequest = chain.request()
|
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()) {
|
if (currAuth.isExpired()) {
|
||||||
val refreshTokenResponse = chain.proceed(HikkaApi.refreshTokenRequest(currAuth.accessToken))
|
val refreshTokenResponse = chain.proceed(HikkaApi.refreshTokenRequest(currAuth.accessToken))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user