fix: Use Windows user agent on Android to please Cloudflare bot detection rules #324
This commit is contained in:
parent
3f81c4451d
commit
c2a7b903a4
|
@ -3,3 +3,13 @@ package com.artemchep.keyguard.platform.util
|
|||
import com.artemchep.keyguard.platform.Platform
|
||||
|
||||
expect val Platform.userAgent: String
|
||||
|
||||
// Taken from:
|
||||
// https://releases.electronjs.org/releases/stable
|
||||
private const val CHROME_VERSION = "126.0.6478.114"
|
||||
|
||||
// Seems like desktop clients always use the Windows user-agents for
|
||||
// privacy reasons.
|
||||
val Platform.defaultUserAgent: String
|
||||
get() = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/$CHROME_VERSION Safari/537.36"
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.artemchep.keyguard.common.util.int
|
|||
import com.artemchep.keyguard.core.store.bitwarden.BitwardenToken
|
||||
import com.artemchep.keyguard.platform.CurrentPlatform
|
||||
import com.artemchep.keyguard.platform.Platform
|
||||
import com.artemchep.keyguard.platform.util.defaultUserAgent
|
||||
import com.artemchep.keyguard.platform.util.userAgent
|
||||
import com.artemchep.keyguard.provider.bitwarden.ServerEnv
|
||||
import com.artemchep.keyguard.provider.bitwarden.ServerTwoFactorToken
|
||||
|
@ -76,7 +77,7 @@ data class BitwardenPersona(
|
|||
clientVersion = CLIENT_VERSION,
|
||||
deviceType = "8",
|
||||
deviceName = "linux",
|
||||
userAgent = userAgent,
|
||||
userAgent = defaultUserAgent,
|
||||
)
|
||||
|
||||
private fun Platform.Desktop.MacOS.bitwardenPersona(
|
||||
|
@ -86,7 +87,7 @@ data class BitwardenPersona(
|
|||
clientVersion = CLIENT_VERSION,
|
||||
deviceType = "7",
|
||||
deviceName = "macos",
|
||||
userAgent = userAgent,
|
||||
userAgent = defaultUserAgent,
|
||||
)
|
||||
|
||||
private fun Platform.Desktop.Windows.bitwardenPersona(
|
||||
|
@ -96,7 +97,7 @@ data class BitwardenPersona(
|
|||
clientVersion = CLIENT_VERSION,
|
||||
deviceType = "6",
|
||||
deviceName = "windows",
|
||||
userAgent = userAgent,
|
||||
userAgent = defaultUserAgent,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -361,7 +361,7 @@ import com.artemchep.keyguard.crypto.CryptoGeneratorJvm
|
|||
import com.artemchep.keyguard.crypto.FileEncryptorImpl
|
||||
import com.artemchep.keyguard.platform.CurrentPlatform
|
||||
import com.artemchep.keyguard.platform.util.isRelease
|
||||
import com.artemchep.keyguard.platform.util.userAgent
|
||||
import com.artemchep.keyguard.provider.bitwarden.api.BitwardenPersona
|
||||
import com.artemchep.keyguard.provider.bitwarden.usecase.CipherUrlCheckImpl
|
||||
import com.artemchep.keyguard.provider.bitwarden.usecase.CipherUrlDuplicateCheckImpl
|
||||
import io.ktor.client.HttpClient
|
||||
|
@ -1295,7 +1295,8 @@ fun globalModuleJvm() = DI.Module(
|
|||
val okHttpClient: OkHttpClient = instance()
|
||||
HttpClient(OkHttp) {
|
||||
install(UserAgent) {
|
||||
agent = CurrentPlatform.userAgent
|
||||
agent = BitwardenPersona.of(CurrentPlatform)
|
||||
.userAgent
|
||||
}
|
||||
engine {
|
||||
preconfigured = okHttpClient
|
||||
|
|
Loading…
Reference in New Issue