Repository navigation
feat(android): add opt-in Trusted Web Activity and Auth Tab support - #961
Conversation
Add useTrustedWebActivity and useAuthTab to CustomTabsOptions. Both are off by default and apply to web auth login and logout on Android. When both are set, Trusted Web Activity takes precedence (Auth0.Android behaviour). Co-Authored-By: Claude
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (3)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Co-Authored-By: Claude <noreply@anthropic.com>
|
|
||
| buildCustomTabsOptions(args)?.let { builder.withCustomTabsOptions(it) } | ||
|
|
||
| // TWA and Auth Tab are mutually exclusive; if both are set, TWA wins |
There was a problem hiding this comment.
@utkrishtsahu this is handled inside auth0.android right?
There was a problem hiding this comment.
Yes, Auth0.Android resolves it: if both are set, TWA wins. We just forward the flags. I've reworded the comment to say that.
|
|
||
| Both launch mechanisms are opt-in and are enabled through `CustomTabsOptions`. They apply to `login` and `logout`, and are ignored on iOS, macOS, Windows and web. | ||
|
|
||
| - **Auth Tab** uses the Chrome Custom Tabs Activity Result API instead of inferring the result from the activity lifecycle. This avoids spurious `isUserCancelledException` errors when Chrome is minimized. It requires Chrome 137+; older browsers fall back to a standard Custom Tab. |
There was a problem hiding this comment.
we can mention authtab supporting ephemeral browsing but not TWA
There was a problem hiding this comment.
added an "Ephemeral sessions" note. It needs Auth0.Android 4.1.0 (older versions drop the flag for Auth Tab), so I bumped the dependency from 4.0.0 to 4.1.0. That bump also fixes Auth Tab logout, which fails on 4.0.0.
| /// spurious user-cancelled errors caused by Chrome being minimized. It | ||
| /// requires Chrome 137+; older browsers fall back to a standard Custom Tab. | ||
| /// Defaults to `false`. Ignored when [useTrustedWebActivity] is `true`. | ||
| final bool? useAuthTab; |
There was a problem hiding this comment.
Why are these two properties marked nullable. They are boolean. The default value can be false
There was a problem hiding this comment.
Both are plain bool now with a default of false, and the tests expect false instead of null.
Make useTrustedWebActivity and useAuthTab non-nullable (default false), document ephemeral session behaviour for Auth Tab and TWA, and bump Auth0.Android to 4.1.0 (Auth Tab logout fix and ephemeral support). Co-Authored-By: Claude
| | `backgroundInteractionEnabled` | `bool?` | Whether the user can interact with the app behind the partial tab. Defaults to `false`. | | ||
| | `allowedBrowsers` | `List<String>` | Allowlist of browser packages for Custom Tabs. | | ||
| | `useTrustedWebActivity` | `bool?` | Launch the browser as a [Trusted Web Activity](#using-trusted-web-activity-or-auth-tab-android-only). Defaults to `false`. | | ||
| | `useAuthTab` | `bool?` | Launch the browser as an [Auth Tab](#using-trusted-web-activity-or-auth-tab-android-only). Defaults to `false`. | |
There was a problem hiding this comment.
Nit : These are non-null properties now
Co-Authored-By: Claude
4.1.0 adds an optional organization parameter to resetPassword, so the two-argument call compiles to a static default-args helper that Mockito cannot stub. Stub the three-argument method instead. Co-Authored-By: Claude
📋 Changes
Adds opt-in support for Trusted Web Activity (TWA) and Auth Tab on Android, using the launch mechanisms Auth0.Android already provides (
withTrustedWebActivity()/withAuthTab()). Both are off by default, so existing behaviour is unchanged.useEphemeralSession) are honoured on Auth Tab.auth0_flutter_platform_interfaceCustomTabsOptions: added two fields,bool useTrustedWebActivityandbool useAuthTab, both non-nullable and defaulting tofalse. Both are included intoMap(). This is additive and non-breaking; no existing signatures change.auth0_flutter(Android)LoginWebAuthRequestHandlerandLogoutWebAuthRequestHandlerread the flags from thecustomTabsOptionsmap and callwithTrustedWebActivity()/withAuthTab()only when the flag istrue.true, Auth0.Android resolves the conflict and TWA takes precedence. This is documented on the Dart fields and inEXAMPLES.md.com.auth0.android:auth0from4.0.0to4.1.0. 4.0.0 cannot do Auth Tab logout (it fails witha0.invalid_authorize_url; fixed upstream in 4.0.1), and 4.1.0 adds ephemeral-session support for Auth Tab. 4.1.0 contains only additive changes.Docs
EXAMPLES.md: new "Using Trusted Web Activity or Auth Tab (Android only)" section (including an "Ephemeral sessions" note), two new rows in theCustomTabsOptionstable, and a table-of-contents entry.Usage
Design note: the flags live on the existing
CustomTabsOptionsrather than as new top-levellogin()/logout()parameters, which keeps Android browser configuration in one place and avoids growing the method signatures.🎯 Testing
Automated (added in this PR)
auth0_flutter_platform_interface/test/custom_tabs_options_test.dart(3 tests):toMap()includes both flags, both default tofalse, and both are passed throughWebAuthLoginOptionsandWebAuthLogoutOptions.auth0_flutter/test/mobile/web_authentication_test.dart(2 tests): the flags are passed through to the platform onlogin, and they default tofalse.LoginWebAuthRequestHandlerTest.ktandLogoutWebAuthRequestHandlerTest.kt(5 tests each): TWA only, Auth Tab only, both set, bothfalse, andcustomTabsOptionsabsent. Each case verifies exactly which builder methods are called. These run in theRun native Android unit testsCI job; I could not run them locally.Manual, on a device
Pixel 10, Android 17, Chrome 154, Auth0.Android 4.1.0, using the example app with a custom URL scheme redirect: