Skip to content

Commit bb432da

Browse files
authored
feat(auth): Added support for Android private browsing (#6336)
* Added support for setEphemeralBrowsingEnabled * Updated Auth Android unit test
1 parent 77ac12f commit bb432da

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPlugin.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,12 @@ open class AmplifyAuthCognitoPlugin :
433433
/**
434434
* Launches [url] in a Custom Tab.
435435
*/
436-
open fun launchUrl(url: String, browserPackageName: String?) {
436+
open fun launchUrl(url: String, browserPackageName: String?, preferPrivateSession: Boolean) {
437437
if (mainActivity == null) {
438438
throw HostedUiException.UNKNOWN("No activity found")
439439
}
440440
val intent = CustomTabsIntent.Builder().apply {
441+
setEphemeralBrowsingEnabled(preferPrivateSession)
441442
setShareState(CustomTabsIntent.SHARE_STATE_OFF)
442443
}.build()
443444
val useBrowserPackage = browserPackageName
@@ -469,9 +470,6 @@ open class AmplifyAuthCognitoPlugin :
469470

470471
/**
471472
* Launch the sign in URL.
472-
*
473-
* Note: [preferPrivateSession] currently has no effect on Android since it is not supported in
474-
* custom tabs.
475473
*/
476474
override fun signInWithUrl(
477475
url: String,
@@ -482,7 +480,7 @@ open class AmplifyAuthCognitoPlugin :
482480
) {
483481
val result = AtomicResult(callback, "signIn")
484482
try {
485-
launchUrl(url, browserPackageName)
483+
launchUrl(url, browserPackageName, preferPrivateSession)
486484
signInResult = result
487485
} catch (e: Throwable) {
488486
result(Result.failure(HostedUiException.fromThrowable(e)))
@@ -501,7 +499,7 @@ open class AmplifyAuthCognitoPlugin :
501499
) {
502500
val result = AtomicResult(callback, "signOut")
503501
try {
504-
launchUrl(url, browserPackageName)
502+
launchUrl(url, browserPackageName, preferPrivateSession)
505503
signOutResult = result
506504
} catch (e: Throwable) {
507505
result(Result.failure(HostedUiException.fromThrowable(e)))

packages/auth/amplify_auth_cognito/android/src/test/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPluginTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class AmplifyAuthCognitoPluginTest {
3232
@Test
3333
fun convertsCancelledException() {
3434
val mockPlugin = object : AmplifyAuthCognitoPlugin() {
35-
override fun launchUrl(url: String, browserPackageName: String?) {
35+
override fun launchUrl(url: String, browserPackageName: String?, preferPrivateSession: Boolean) {
3636
throw HostedUiException.CANCELLED()
3737
}
3838
}
@@ -70,7 +70,7 @@ internal class AmplifyAuthCognitoPluginTest {
7070
fun convertsUnknownException() {
7171
val aMessage = "a message"
7272
val mockPlugin = object : AmplifyAuthCognitoPlugin() {
73-
override fun launchUrl(url: String, browserPackageName: String?) {
73+
override fun launchUrl(url: String, browserPackageName: String?, preferPrivateSession: Boolean) {
7474
throw HostedUiException.UNKNOWN(aMessage)
7575
}
7676
}

packages/auth/amplify_auth_cognito_dart/lib/src/model/signin/cognito_sign_in_with_web_ui_plugin_options.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ class CognitoSignInWithWebUIPluginOptions extends SignInWithWebUIPluginOptions {
2222
) => _$CognitoSignInWithWebUIPluginOptionsFromJson(json);
2323

2424
/// {@template amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.private_session}
25-
/// iOS-only: Starts the webUI signin in a private browser session, if supported by the current browser.
25+
/// Starts the webUI signin in a private browser session, if supported by the current browser.
2626
///
27-
/// Note that this value internally sets `prefersEphemeralWebBrowserSession` in ASWebAuthenticationSession.
27+
/// Note that on iOS this value internally sets `prefersEphemeralWebBrowserSession` in ASWebAuthenticationSession.
2828
/// As per Apple documentation, Whether the request is honored depends on the user’s default web browser.
2929
/// Safari always honors the request.
3030
///
31+
/// Note that on Android this value internally sets `setEphemeralBrowsingEnabled` in CustomTabsIntent.
32+
///
3133
/// Defaults to `false`.
3234
/// {@endtemplate}
3335
final bool isPreferPrivateSession;

0 commit comments

Comments
 (0)