AuthViewModel: Drop dependency upon kovenant
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -46,7 +46,6 @@ import com.aurora.store.viewmodel.BaseAndroidViewModel
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.supervisorScope
|
import kotlinx.coroutines.supervisorScope
|
||||||
import nl.komponents.kovenant.task
|
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -78,17 +77,18 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
|
|||||||
|
|
||||||
fun buildGoogleAuthData(email: String, aasToken: String) {
|
fun buildGoogleAuthData(email: String, aasToken: String) {
|
||||||
liveData.postValue(AuthState.Fetching)
|
liveData.postValue(AuthState.Fetching)
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
var properties = NativeDeviceInfoProvider(getApplication()).getNativeDeviceProperties()
|
||||||
|
if (spoofProvider.isDeviceSpoofEnabled())
|
||||||
|
properties = spoofProvider.getSpoofDeviceProperties()
|
||||||
|
|
||||||
task {
|
val authData = AuthHelper.build(email, aasToken, properties)
|
||||||
var properties = NativeDeviceInfoProvider(getApplication()).getNativeDeviceProperties()
|
verifyAndSaveAuth(authData, AccountType.GOOGLE)
|
||||||
if (spoofProvider.isDeviceSpoofEnabled())
|
} catch (exception: Exception) {
|
||||||
properties = spoofProvider.getSpoofDeviceProperties()
|
updateStatus("Failed to generate Session")
|
||||||
|
Log.e(TAG, "Failed to generate Session", exception)
|
||||||
return@task AuthHelper.build(email, aasToken, properties)
|
}
|
||||||
} success {
|
|
||||||
verifyAndSaveAuth(it, AccountType.GOOGLE)
|
|
||||||
} fail {
|
|
||||||
updateStatus("Failed to generate Session")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,93 +107,97 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
|
|||||||
|
|
||||||
private fun buildSecureAnonymousAuthData() {
|
private fun buildSecureAnonymousAuthData() {
|
||||||
liveData.postValue(AuthState.Fetching)
|
liveData.postValue(AuthState.Fetching)
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
var properties = NativeDeviceInfoProvider(getApplication())
|
||||||
|
.getNativeDeviceProperties()
|
||||||
|
|
||||||
task {
|
if (spoofProvider.isDeviceSpoofEnabled())
|
||||||
var properties = NativeDeviceInfoProvider(getApplication())
|
properties = spoofProvider.getSpoofDeviceProperties()
|
||||||
.getNativeDeviceProperties()
|
|
||||||
|
|
||||||
if (spoofProvider.isDeviceSpoofEnabled())
|
val playResponse = HttpClient
|
||||||
properties = spoofProvider.getSpoofDeviceProperties()
|
.getPreferredClient()
|
||||||
|
.postAuth(
|
||||||
val playResponse = HttpClient
|
Constants.URL_DISPENSER,
|
||||||
.getPreferredClient()
|
gson.toJson(properties).toByteArray()
|
||||||
.postAuth(
|
|
||||||
Constants.URL_DISPENSER,
|
|
||||||
gson.toJson(properties).toByteArray()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (playResponse.isSuccessful) {
|
|
||||||
return@task gson.fromJson(
|
|
||||||
String(playResponse.responseBytes),
|
|
||||||
AuthData::class.java
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
when (playResponse.code) {
|
|
||||||
404 -> throw Exception("Server unreachable")
|
|
||||||
429 -> throw Exception("Oops, You are rate limited")
|
|
||||||
503 -> throw Exception(
|
|
||||||
(getApplication() as Context).getString(R.string.server_maintenance)
|
|
||||||
)
|
)
|
||||||
else -> throw Exception(playResponse.errorString)
|
|
||||||
|
if (playResponse.isSuccessful) {
|
||||||
|
val authData = gson.fromJson(
|
||||||
|
String(playResponse.responseBytes),
|
||||||
|
AuthData::class.java
|
||||||
|
)
|
||||||
|
|
||||||
|
//Set AuthData as anonymous
|
||||||
|
authData.isAnonymous = true
|
||||||
|
verifyAndSaveAuth(authData, AccountType.ANONYMOUS)
|
||||||
|
} else {
|
||||||
|
val ctx = getApplication() as Context
|
||||||
|
when (playResponse.code) {
|
||||||
|
404 -> throw Exception("Server unreachable")
|
||||||
|
429 -> throw Exception("Oops, You are rate limited")
|
||||||
|
503 -> throw Exception(ctx.getString(R.string.server_maintenance))
|
||||||
|
else -> throw Exception(playResponse.errorString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
updateStatus(exception.message.toString())
|
||||||
|
Log.e(TAG, "Failed to generate Session", exception)
|
||||||
}
|
}
|
||||||
} success {
|
|
||||||
//Set AuthData as anonymous
|
|
||||||
it.isAnonymous = true
|
|
||||||
verifyAndSaveAuth(it, AccountType.ANONYMOUS)
|
|
||||||
} fail {
|
|
||||||
updateStatus(it.message.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildInSecureAnonymousAuthData() {
|
fun buildInSecureAnonymousAuthData() {
|
||||||
liveData.postValue(AuthState.Fetching)
|
liveData.postValue(AuthState.Fetching)
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
var properties = NativeDeviceInfoProvider(getApplication())
|
||||||
|
.getNativeDeviceProperties()
|
||||||
|
|
||||||
task {
|
if (spoofProvider.isDeviceSpoofEnabled())
|
||||||
var properties = NativeDeviceInfoProvider(getApplication())
|
properties = spoofProvider.getSpoofDeviceProperties()
|
||||||
.getNativeDeviceProperties()
|
|
||||||
|
|
||||||
if (spoofProvider.isDeviceSpoofEnabled())
|
val playResponse = HttpClient
|
||||||
properties = spoofProvider.getSpoofDeviceProperties()
|
.getPreferredClient()
|
||||||
|
.getAuth(
|
||||||
val playResponse = HttpClient
|
Constants.URL_DISPENSER
|
||||||
.getPreferredClient()
|
|
||||||
.getAuth(
|
|
||||||
Constants.URL_DISPENSER
|
|
||||||
)
|
|
||||||
|
|
||||||
val insecureAuth: InsecureAuth
|
|
||||||
|
|
||||||
if (playResponse.isSuccessful) {
|
|
||||||
insecureAuth = gson.fromJson(
|
|
||||||
String(playResponse.responseBytes),
|
|
||||||
InsecureAuth::class.java
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
when (playResponse.code) {
|
|
||||||
404 -> throw Exception("Server unreachable")
|
|
||||||
429 -> throw Exception("Oops, You are rate limited")
|
|
||||||
503 -> throw Exception(
|
|
||||||
(getApplication() as Context).getString(R.string.server_maintenance)
|
|
||||||
)
|
)
|
||||||
else -> throw Exception(playResponse.errorString)
|
|
||||||
|
val insecureAuth: InsecureAuth
|
||||||
|
|
||||||
|
if (playResponse.isSuccessful) {
|
||||||
|
insecureAuth = gson.fromJson(
|
||||||
|
String(playResponse.responseBytes),
|
||||||
|
InsecureAuth::class.java
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
when (playResponse.code) {
|
||||||
|
404 -> throw Exception("Server unreachable")
|
||||||
|
429 -> throw Exception("Oops, You are rate limited")
|
||||||
|
503 -> throw Exception(
|
||||||
|
(getApplication() as Context).getString(R.string.server_maintenance)
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> throw Exception(playResponse.errorString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deviceInfoProvider =
|
||||||
|
DeviceInfoProvider(properties, Locale.getDefault().toString())
|
||||||
|
val authData = AuthHelper.buildInsecure(
|
||||||
|
insecureAuth.email,
|
||||||
|
insecureAuth.auth,
|
||||||
|
Locale.getDefault(),
|
||||||
|
deviceInfoProvider
|
||||||
|
)
|
||||||
|
|
||||||
|
//Set AuthData as anonymous
|
||||||
|
authData.isAnonymous = true
|
||||||
|
verifyAndSaveAuth(authData, AccountType.ANONYMOUS)
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
updateStatus(exception.message.toString())
|
||||||
|
Log.e(TAG, "Failed to generate Session", exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
val deviceInfoProvider = DeviceInfoProvider(properties, Locale.getDefault().toString())
|
|
||||||
|
|
||||||
AuthHelper.buildInsecure(
|
|
||||||
insecureAuth.email,
|
|
||||||
insecureAuth.auth,
|
|
||||||
Locale.getDefault(),
|
|
||||||
deviceInfoProvider
|
|
||||||
)
|
|
||||||
} success {
|
|
||||||
//Set AuthData as anonymous
|
|
||||||
it.isAnonymous = true
|
|
||||||
verifyAndSaveAuth(it, AccountType.ANONYMOUS)
|
|
||||||
} fail {
|
|
||||||
updateStatus(it.message.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user