feat: Added Auth tab support#962
Conversation
…roid into auth_tab_support
| @Suppress("DEPRECATION") | ||
| public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
| super.onActivityResult(requestCode, resultCode, data) | ||
| // If the Activity Result API (e.g. auth tab) already handled this result and called |
There was a problem hiding this comment.
remove this generated comment
There was a problem hiding this comment.
This is added intentionally to highlight why this if check is needed
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| // Auth Tab results are delivered via the Activity Result API callback (onAuthTabResult) |
There was a problem hiding this comment.
remove this generated comment
There was a problem hiding this comment.
This is added intentionally to highlight why this if check is needed
| customTabsClientMock = Mockito.mockStatic(CustomTabsClient.class); | ||
| customTabsClientMock.when(() -> CustomTabsClient.isAuthTabSupported(eq(context), any(String.class))).thenReturn(true); | ||
|
|
||
| CustomTabsOptions ctOptions = CustomTabsOptions.newBuilder() |
There was a problem hiding this comment.
missing .withAuthTab() — test never enters the auth tab code path, passes for the wrong reason
There was a problem hiding this comment.
Good catch. Fixed
There was a problem hiding this comment.
the test now has .withAuthTab() but still uses the default BrowserPicker (no mock returning a package). This means preferredPackage will be null, so the method falls back at the first guard (preferredPackage == null) — not at the scheme check it's supposed to test. The test still passes for the wrong reason, just at a different fallback point.
| @ExperimentalAuth0Api | ||
| @NonNull | ||
| public Builder withEphemeralBrowsing() { | ||
| Builder withEphemeralBrowsing() { |
There was a problem hiding this comment.
visibility reduced from public to package-private without callout; this is a breaking API change
There was a problem hiding this comment.
No.. this is inside the CustomTabsOptions class. Not the public API
| import com.google.androidbrowserhelper.trusted.TwaLauncher | ||
|
|
||
| public open class AuthenticationActivity : Activity() { | ||
| public open class AuthenticationActivity : ComponentActivity() { |
There was a problem hiding this comment.
ComponentActivity() — base class change from Activity is public API-breaking for subclassers;
Can we document in V4 migration guide
There was a problem hiding this comment.
this is within the SDK. Not for public APIs. It is open for testing purpose. Do you see scenario where this can fail for users updating to V4 ?
There was a problem hiding this comment.
since this targets v4 and subclassing AuthenticationActivity isn't a documented use case, this is fine. No action needed.
| } | ||
| private var customTabsController: CustomTabsController? = null | ||
| override fun onNewIntent(intent: Intent?) { | ||
| override fun onNewIntent(intent: Intent) { |
There was a problem hiding this comment.
signature changed from nullable to non-null; subclass overrides of the old signature will break
There was a problem hiding this comment.
Again an internal implementation. No effect for consuming clients
| null, | ||
| TwaLauncher.CCT_FALLBACK_STRATEGY | ||
| ); | ||
| } else if (customTabsOptions.isAuthTab()) { |
There was a problem hiding this comment.
else if (customTabsOptions.isAuthTab()) — TWA silently takes priority over Auth Tab; consider logging a warning or documenting this precedence
There was a problem hiding this comment.
Added comments and document to highlight this
| public open class AuthenticationActivity : Activity() { | ||
| public open class AuthenticationActivity : ComponentActivity() { | ||
| private var intentLaunched = false | ||
| internal val authTabResultHandler = AuthTabResultHandler( |
There was a problem hiding this comment.
internal val authTabResultHandler — internal exposes to entire module, not just tests; consider private + @VisibleForTesting(PRIVATE)
There was a problem hiding this comment.
We intentionally chose internal over private + @VisibleForTesting as part of the collaborator pattern
- AuthTabResultHandler is internal itself, so the combination is module-scoped regardless
- The collaborator pattern was specifically chosen to avoid @VisibleForTesting on the activity — adding it back would contradict the design
- Tests in the same module access it cleanly without annotation
| return; | ||
| } | ||
|
|
||
| bindService(); |
There was a problem hiding this comment.
bindService() called before scheme null-check at line 198; if scheme is null, this work is wasted before falling back to launchAsDefault which calls bindService again
There was a problem hiding this comment.
Good point. Moved scheme check above bindService()
| customTabsClientMock = Mockito.mockStatic(CustomTabsClient.class); | ||
| customTabsClientMock.when(() -> CustomTabsClient.isAuthTabSupported(eq(context), any(String.class))).thenReturn(true); | ||
|
|
||
| CustomTabsOptions ctOptions = CustomTabsOptions.newBuilder() |
There was a problem hiding this comment.
the test now has .withAuthTab() but still uses the default BrowserPicker (no mock returning a package). This means preferredPackage will be null, so the method falls back at the first guard (preferredPackage == null) — not at the scheme check it's supposed to test. The test still passes for the wrong reason, just at a different fallback point.
Changes
This PT adds support for Android Auth TabIntent to the
WebAuthenticationlogin and logout flow.References
https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent
Testing
Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. Since this library has unit testing, tests should be added for new functionality and existing tests should complete without errors.
This change adds unit test coverage
This change adds integration test coverage
This change has been tested on the latest version of the platform/language or why not
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors