mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 09:49:25 +02:00
Retry without client authentication in case of errors
This commit is contained in:
parent
3d5efdc3c0
commit
5880ef2885
1 changed files with 11 additions and 6 deletions
|
@ -139,7 +139,10 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendMailLoginCode(mail: String, locale: String, deviceAuthToken: String?): String = withDeviceVerification { client ->
|
override suspend fun sendMailLoginCode(mail: String, locale: String, deviceAuthToken: String?): String =
|
||||||
|
sendMailLoginCode(mail, locale, deviceAuthToken, false)
|
||||||
|
|
||||||
|
private suspend fun sendMailLoginCode(mail: String, locale: String, deviceAuthToken: String?, skipDeviceVerification: Boolean): String = withDeviceVerification (enable = !skipDeviceVerification) { client ->
|
||||||
postJsonRequest(
|
postJsonRequest(
|
||||||
"auth/send-mail-login-code-v2",
|
"auth/send-mail-login-code-v2",
|
||||||
client = client
|
client = client
|
||||||
|
@ -153,14 +156,16 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
|
||||||
try {
|
try {
|
||||||
it.assertSuccess()
|
it.assertSuccess()
|
||||||
} catch (ex: BadRequestHttpError) {
|
} catch (ex: BadRequestHttpError) {
|
||||||
if (deviceAuthToken != null) {
|
if (deviceAuthToken != null || !skipDeviceVerification) {
|
||||||
// retry without device auth token
|
// retry without device auth token
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.d(LOG_TAG, "sendMailLoginCode() try again without deviceAuthToken")
|
Log.d(LOG_TAG, "sendMailLoginCode() try again without deviceAuthToken and device verification")
|
||||||
}
|
}
|
||||||
|
|
||||||
return@use sendMailLoginCode(mail, locale, null)
|
Threads.network.executeAndWait { it.close() }
|
||||||
|
|
||||||
|
return@use sendMailLoginCode(mail, locale, null, true)
|
||||||
} else {
|
} else {
|
||||||
throw ex
|
throw ex
|
||||||
}
|
}
|
||||||
|
@ -685,8 +690,8 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
|
||||||
).waitForResponse()
|
).waitForResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T> withDeviceVerification(block: suspend (client: OkHttpClient) -> T): T {
|
private suspend fun <T> withDeviceVerification(enable: Boolean = true, block: suspend (client: OkHttpClient) -> T): T {
|
||||||
if (VERSION.SDK_INT >= VERSION_CODES.N) {
|
if (VERSION.SDK_INT >= VERSION_CODES.N && enable) {
|
||||||
val keyStoreName = "AndroidKeyStore"
|
val keyStoreName = "AndroidKeyStore"
|
||||||
val keyStore = KeyStore.getInstance(keyStoreName).also { it.load(null) }
|
val keyStore = KeyStore.getInstance(keyStoreName).also { it.load(null) }
|
||||||
val keyId = "temp-" + UUID.randomUUID().toString()
|
val keyId = "temp-" + UUID.randomUUID().toString()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue