mirror of
https://github.com/twofas/2fas-android.git
synced 2025-01-07 06:55:36 +01:00
Fix BE request auth aware
This commit is contained in:
parent
4fafd68950
commit
13670a6cbb
@ -25,6 +25,10 @@ class AuthTracker(
|
||||
reset()
|
||||
}
|
||||
|
||||
fun onBrowserExtRequest() {
|
||||
reset()
|
||||
}
|
||||
|
||||
fun onAuthenticateScreen() {
|
||||
reset()
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ class OtpAuthenticator {
|
||||
private const val HmacSha384 = "HmacSHA384"
|
||||
private const val HmacSha512 = "HmacSHA512"
|
||||
private val keyModulus = mapOf(
|
||||
5 to 10.0.pow(5.toDouble()).toLong(),
|
||||
6 to 10.0.pow(6.toDouble()).toLong(),
|
||||
7 to 10.0.pow(7.toDouble()).toLong(),
|
||||
8 to 10.0.pow(8.toDouble()).toLong(),
|
||||
|
@ -134,7 +134,7 @@ internal fun BackupService.asDomain(
|
||||
secret = secret,
|
||||
name = name,
|
||||
info = otp.account ?: otp.label,
|
||||
authType = otp.tokenType?.let { enumValueOrNull<Service.AuthType>(it) } ?: Service.AuthType.TOTP,
|
||||
authType = otp.tokenType?.let { enumValueOf<Service.AuthType>(it) } ?: Service.AuthType.TOTP,
|
||||
link = otp.link,
|
||||
issuer = otp.issuer,
|
||||
period = otp.period,
|
||||
|
@ -11,6 +11,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":base"))
|
||||
implementation(project(":prefs"))
|
||||
implementation(project(":core:common"))
|
||||
implementation(project(":core:android"))
|
||||
implementation(project(":core:locale"))
|
||||
|
@ -3,15 +3,21 @@ package com.twofasapp.feature.browserext.ui.request
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import com.twofasapp.base.AuthTracker
|
||||
import com.twofasapp.base.lifecycle.AuthAware
|
||||
import com.twofasapp.base.lifecycle.AuthLifecycle
|
||||
import com.twofasapp.data.session.SettingsRepository
|
||||
import com.twofasapp.designsystem.MainAppTheme
|
||||
import com.twofasapp.designsystem.activity.ActivityHelper
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestPayload
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
class BrowserExtRequestActivity : ComponentActivity() {
|
||||
class BrowserExtRequestActivity : ComponentActivity(), AuthAware {
|
||||
|
||||
private val settingsRepository: SettingsRepository by inject()
|
||||
private val authTracker: AuthTracker by inject()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
ActivityHelper.onCreate(
|
||||
@ -23,10 +29,22 @@ class BrowserExtRequestActivity : ComponentActivity() {
|
||||
|
||||
val payload = intent.getParcelableExtra<BrowserExtRequestPayload>(BrowserExtRequestPayload.Key)!!
|
||||
|
||||
authTracker.onBrowserExtRequest()
|
||||
|
||||
lifecycle.addObserver(
|
||||
AuthLifecycle(
|
||||
authTracker = get(),
|
||||
navigator = get { parametersOf(this) },
|
||||
authAware = this as? AuthAware
|
||||
)
|
||||
)
|
||||
|
||||
setContent {
|
||||
MainAppTheme {
|
||||
BrowserExtRequestScreen(payload = payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAuthenticated() = Unit
|
||||
}
|
@ -24,8 +24,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestPayload
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestReceiver
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.twofasapp.common.domain.Service
|
||||
import com.twofasapp.designsystem.TwTheme
|
||||
import com.twofasapp.designsystem.common.TwSwitch
|
||||
@ -33,7 +32,10 @@ import com.twofasapp.designsystem.common.TwTopAppBar
|
||||
import com.twofasapp.designsystem.ktx.currentActivity
|
||||
import com.twofasapp.designsystem.service.DsServiceSimple
|
||||
import com.twofasapp.designsystem.service.asState
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestPayload
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestReceiver
|
||||
import com.twofasapp.locale.TwLocale
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
|
||||
@Composable
|
||||
@ -52,22 +54,24 @@ internal fun BrowserExtRequestScreen(
|
||||
uiState = uiState,
|
||||
onSaveMyChoiceToggle = { viewModel.toggleSaveMyChoice() },
|
||||
onServiceClick = { service ->
|
||||
viewModel.assignDomain(service)
|
||||
activity.lifecycleScope.launch {
|
||||
viewModel.assignDomain(service)
|
||||
|
||||
// Clear notification
|
||||
NotificationManagerCompat
|
||||
.from(activity)
|
||||
.cancel(null, payload.requestId.hashCode())
|
||||
// Clear notification
|
||||
NotificationManagerCompat
|
||||
.from(activity)
|
||||
.cancel(null, payload.requestId.hashCode())
|
||||
|
||||
// Launch broadcast
|
||||
val intent = Intent(activity, BrowserExtRequestReceiver::class.java)
|
||||
.apply {
|
||||
action = BrowserExtRequestReceiver.ACTION
|
||||
putExtra(BrowserExtRequestPayload.Key, payload.copy(serviceId = service.id))
|
||||
}
|
||||
// Launch broadcast
|
||||
val intent = Intent(activity, BrowserExtRequestReceiver::class.java)
|
||||
.apply {
|
||||
action = BrowserExtRequestReceiver.ACTION
|
||||
putExtra(BrowserExtRequestPayload.Key, payload.copy(serviceId = service.id))
|
||||
}
|
||||
|
||||
activity.sendBroadcast(intent)
|
||||
activity.finish()
|
||||
activity.finish()
|
||||
activity.sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -2,18 +2,21 @@ package com.twofasapp.feature.browserext.ui.requestapprove
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.material3.Surface
|
||||
import com.twofasapp.base.AuthTracker
|
||||
import com.twofasapp.base.lifecycle.AuthAware
|
||||
import com.twofasapp.base.lifecycle.AuthLifecycle
|
||||
import com.twofasapp.data.session.SettingsRepository
|
||||
import com.twofasapp.designsystem.MainAppTheme
|
||||
import com.twofasapp.designsystem.activity.ActivityHelper
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestPayload
|
||||
import com.twofasapp.feature.browserext.notification.BrowserExtRequestReceiver
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
class BrowserExtRequestApproveActivity : ComponentActivity() {
|
||||
class BrowserExtRequestApproveActivity : ComponentActivity(), AuthAware {
|
||||
|
||||
private val settingsRepository: SettingsRepository by inject()
|
||||
private val authTracker: AuthTracker by inject()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
ActivityHelper.onCreate(
|
||||
@ -22,15 +25,28 @@ class BrowserExtRequestApproveActivity : ComponentActivity() {
|
||||
allowScreenshots = settingsRepository.getAppSettings().allowScreenshots,
|
||||
)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val payload = intent.getParcelableExtra<BrowserExtRequestPayload>(BrowserExtRequestPayload.Key)!!
|
||||
|
||||
setContent {
|
||||
MainAppTheme {
|
||||
Surface {
|
||||
sendBroadcast(BrowserExtRequestReceiver.createIntent(this, payload))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
if (payload.action == BrowserExtRequestPayload.Action.Deny) {
|
||||
sendBroadcast(BrowserExtRequestReceiver.createIntent(this, payload))
|
||||
finish()
|
||||
} else {
|
||||
authTracker.onBrowserExtRequest()
|
||||
|
||||
lifecycle.addObserver(
|
||||
AuthLifecycle(
|
||||
authTracker = get(),
|
||||
navigator = get { parametersOf(this) },
|
||||
authAware = this as? AuthAware
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAuthenticated() {
|
||||
val payload = intent.getParcelableExtra<BrowserExtRequestPayload>(BrowserExtRequestPayload.Key)!!
|
||||
sendBroadcast(BrowserExtRequestReceiver.createIntent(this, payload))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user