diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/Hikka.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/Hikka.kt index 12524e716..3bd43a574 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/Hikka.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/Hikka.kt @@ -128,9 +128,9 @@ class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker { override suspend fun login(username: String, password: String) = login(password) - suspend fun login(code: String) { + suspend fun login(reference: String) { try { - val oauth = api.accessToken(code) + val oauth = api.accessToken(reference) interceptor.setAuth(oauth) val user = api.getCurrentUser() saveCredentials(user.reference, oauth.accessToken) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaApi.kt index 18108ddb6..6cb9fd9d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaApi.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.track.hikka import android.net.Uri import androidx.core.net.toUri import eu.kanade.tachiyomi.data.database.models.Track -import eu.kanade.tachiyomi.data.track.hikka.dto.HKAuthTokenInfo import eu.kanade.tachiyomi.data.track.hikka.dto.HKManga import eu.kanade.tachiyomi.data.track.hikka.dto.HKMangaPagination import eu.kanade.tachiyomi.data.track.hikka.dto.HKOAuth @@ -48,24 +47,16 @@ class HikkaApi( } } - private suspend fun getTokenInfo(accessToken: String): HKAuthTokenInfo { + suspend fun accessToken(reference: String): HKOAuth { return withIOContext { with(json) { - client.newCall(authTokenInfo(accessToken)) + client.newCall(authTokenCreate(reference)) .awaitSuccess() - .parseAs() + .parseAs() } } } - suspend fun accessToken(code: String): HKOAuth { - return withIOContext { - val tokenInfo = getTokenInfo(code) - val oauth = HKOAuth(code, tokenInfo.expiration) - oauth - } - } - suspend fun searchManga(query: String): List { return withIOContext { val url = "$BASE_API_URL/manga".toUri().buildUpon() @@ -189,10 +180,13 @@ class HikkaApi( const val BASE_API_URL = "https://hikka.io/api" const val BASE_URL = "https://hikka.io" private const val SCOPE = "readlist,read:user-details" - private const val REFERENCE = "49eda83d-baa6-45f8-9936-b2a41d944da4" + private const val CLIENT_REFERENCE = "49eda83d-baa6-45f8-9936-b2a41d944da4" + private const val CLIENT_SECRET = "8Zxzs13Pvikx6m_4rwjF7t2BxxnEb0wWtXIRQ_68HyCvmdhGE9hdfz" + + "SL1Pas4h927LaV2ocjVoc--S_vmorHEWWh42Z_z70j-wSFYsraQQ98" + + "hiOeTH2BaDf77ZcA9W5Z" fun authUrl(): Uri = "$BASE_URL/oauth".toUri().buildUpon() - .appendQueryParameter("reference", REFERENCE) + .appendQueryParameter("reference", CLIENT_REFERENCE) .appendQueryParameter("scope", SCOPE) .build() @@ -204,6 +198,14 @@ class HikkaApi( return GET("$BASE_API_URL/user/me", headers = headers) // Any request with auth } + fun authTokenCreate(reference: String): Request { + val payload = buildJsonObject { + put("request_reference", reference) + put("client_secret", CLIENT_SECRET) + } + return POST("$BASE_API_URL/auth/token", body = payload.toString().toRequestBody(jsonMime)) + } + fun authTokenInfo(accessToken: String): Request { val headers = Headers.Builder() .add("auth", accessToken) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt index e555ab3cc..062b88861 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt @@ -30,7 +30,7 @@ class HikkaInterceptor(private val hikka: Hikka) : Interceptor { } val authTokenInfo = json.decodeFromString(authTokenInfoResponse.body.string()) - setAuth(HKOAuth(oauth!!.accessToken, authTokenInfo.expiration)) + setAuth(HKOAuth(oauth!!.accessToken, authTokenInfo.expiration, authTokenInfo.created)) } val authRequest = originalRequest.newBuilder() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/dto/HKOAuth.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/dto/HKOAuth.kt index 69f34a74d..1c72733e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/dto/HKOAuth.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/dto/HKOAuth.kt @@ -1,11 +1,14 @@ package eu.kanade.tachiyomi.data.track.hikka.dto +import android.util.Log +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class HKOAuth( - val accessToken: String, + @SerialName("secret") val accessToken: String, val expiration: Long, + val created: Long, ) { fun isExpired(): Boolean { return (expiration - 43200) < (System.currentTimeMillis() / 1000) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginActivity.kt index 5f1ef2c69..9487e57f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginActivity.kt @@ -70,10 +70,10 @@ class TrackLoginActivity : BaseOAuthLoginActivity() { } private fun handleHikka(data: Uri) { - val code = data.getQueryParameter("code") - if (code != null) { + val reference = data.getQueryParameter("reference") + if (reference != null) { lifecycleScope.launchIO { - trackerManager.hikka.login(code) + trackerManager.hikka.login(reference) returnToSettings() } } else {