Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/src/main/java/ch/rhosys/email/data/auth/AuthressLoginClient.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.rhosys.email.data.auth

import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import ch.rhosys.email.BuildConfig
Expand Down Expand Up @@ -154,7 +155,7 @@ class AuthressLoginClient(
)

withContext(Dispatchers.Main) {
CustomTabsIntent.Builder().build().launchUrl(context, Uri.parse(authenticationUrl))
launchAuthenticationUrl(authenticationUrl)
}
}.onFailure { logger.error("Authress", "authenticate() failed", it) }

Expand Down Expand Up @@ -213,6 +214,19 @@ class AuthressLoginClient(
fun isRedirect(uri: Uri?): Boolean =
uri != null && uri.toString().startsWith(redirectUri)

/**
* [context] here is always the Application context (this client is built
* once in [ch.rhosys.email.di.AppContainer], never per-Activity), so the
* Custom Tab intent needs FLAG_ACTIVITY_NEW_TASK explicitly — launchUrl
* doesn't add it, and starting an activity from a non-Activity context
* without it throws.
*/
private fun launchAuthenticationUrl(url: String) {
val customTabsIntent = CustomTabsIntent.Builder().build()
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
customTabsIntent.launchUrl(context, Uri.parse(url))
}

// ── session ─────────────────────────────────────────────────────────────

/**
Expand Down Expand Up @@ -329,7 +343,7 @@ class AuthressLoginClient(
)

withContext(Dispatchers.Main) {
CustomTabsIntent.Builder().build().launchUrl(context, Uri.parse(authenticationUrl))
launchAuthenticationUrl(authenticationUrl)
}
AuthenticationResponse(authenticationUrl, authenticationRequestId)
}.onFailure { logger.error("Authress", "linkIdentity() failed", it) }
Expand Down