mirror of
https://github.com/mihonapp/mihon.git
synced 2025-03-13 16:20:08 +01:00
Fix Bangumi tracker losing track of login expiration (#1681)
* Fix Bangumi tracking losing track of login state kotlinx.serialization does NOT serialize default values (like createdAt in BGMOAuth.kt), so every time the Bangumi tracker deserialized the tracker OAuth, createdAt was set to the time of the read, not the time of issuance. Separately, BangumiInterceptor did correctly fetch new OAuth credentials upon detected expiry of the stored credentials and saved them, but did not use them for the current request (the new credentials were used for all subsequent requests only). This led to 401 errors from Bangumi because the expired access_token was provided. A subsequent request using the newly acquired access_token would end up being successful. * Add CHANGELOG.md entry
This commit is contained in:
parent
503d0be667
commit
dce6aacf02
@ -17,6 +17,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix MAL `main_picture` nullability breaking search if a result doesn't have a cover set ([@MajorTanya](https://github.com/MajorTanya)) ([#1618](https://github.com/mihonapp/mihon/pull/1618))
|
- Fix MAL `main_picture` nullability breaking search if a result doesn't have a cover set ([@MajorTanya](https://github.com/MajorTanya)) ([#1618](https://github.com/mihonapp/mihon/pull/1618))
|
||||||
|
- Fix Bangumi tracking 401 errors due to Mihon sending expired credentials ([@MajorTanya](https://github.com/MajorTanya)) ([#1681](https://github.com/mihonapp/mihon/pull/1681))
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
- Add zoned "Current time" to debug info and include year & timezone in logcat output ([@MajorTanya](https://github.com/MajorTanya)) ([#1672](https://github.com/mihonapp/mihon/pull/1672))
|
- Add zoned "Current time" to debug info and include year & timezone in logcat output ([@MajorTanya](https://github.com/MajorTanya)) ([#1672](https://github.com/mihonapp/mihon/pull/1672))
|
||||||
|
@ -21,12 +21,13 @@ class BangumiInterceptor(private val bangumi: Bangumi) : Interceptor {
|
|||||||
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 Bangumi")
|
var currAuth: BGMOAuth = oauth ?: throw Exception("Not authenticated with Bangumi")
|
||||||
|
|
||||||
if (currAuth.isExpired()) {
|
if (currAuth.isExpired()) {
|
||||||
val response = chain.proceed(BangumiApi.refreshTokenRequest(currAuth.refreshToken!!))
|
val response = chain.proceed(BangumiApi.refreshTokenRequest(currAuth.refreshToken!!))
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
newAuth(json.decodeFromString<BGMOAuth>(response.body.string()))
|
currAuth = json.decodeFromString<BGMOAuth>(response.body.string())
|
||||||
|
newAuth(currAuth)
|
||||||
} else {
|
} else {
|
||||||
response.close()
|
response.close()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.data.track.bangumi.dto
|
package eu.kanade.tachiyomi.data.track.bangumi.dto
|
||||||
|
|
||||||
|
import kotlinx.serialization.EncodeDefault
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ data class BGMOAuth(
|
|||||||
@SerialName("token_type")
|
@SerialName("token_type")
|
||||||
val tokenType: String,
|
val tokenType: String,
|
||||||
@SerialName("created_at")
|
@SerialName("created_at")
|
||||||
|
@EncodeDefault
|
||||||
val createdAt: Long = System.currentTimeMillis() / 1000,
|
val createdAt: Long = System.currentTimeMillis() / 1000,
|
||||||
@SerialName("expires_in")
|
@SerialName("expires_in")
|
||||||
val expiresIn: Long,
|
val expiresIn: Long,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user