Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ private void launchAsAuthTab(@NonNull Context context, @NonNull Uri uri, @NonNul
return;
}
String redirectUri = uri.getQueryParameter("redirect_uri");
if (redirectUri == null) {
redirectUri = uri.getQueryParameter("returnTo");
}
if (redirectUri == null) {
Log.e(TAG, "Could not determine redirect URI from authorize URL. This is likely a configuration error.");
if (failureCallback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,33 @@ public void shouldLaunchAsAuthTabWhenSupportedByBrowser() throws Exception {
verify(context, never()).startActivity(any(Intent.class));
}

@Test
public void shouldLaunchAsAuthTabUsingReturnToWhenRedirectUriIsAbsent() throws Exception {
customTabsClientMock = Mockito.mockStatic(CustomTabsClient.class);
customTabsClientMock.when(() ->
CustomTabsClient.isAuthTabSupported(any(), eq(DEFAULT_BROWSER_PACKAGE))
).thenReturn(true);

@SuppressWarnings("unchecked")
ActivityResultLauncher<Intent> mockAuthTabLauncher = mock(ActivityResultLauncher.class);

BrowserPicker browserPicker = mock(BrowserPicker.class);
when(browserPicker.getBestBrowserPackage(context.getPackageManager())).thenReturn(DEFAULT_BROWSER_PACKAGE);
CustomTabsOptions ctOptions = CustomTabsOptions.newBuilder()
.withBrowserPicker(browserPicker)
.withAuthTab()
.build();

CustomTabsController authTabController =
new CustomTabsController(context, ctOptions, twaLauncher, mockAuthTabLauncher);

Uri logoutUri = Uri.parse("https://example.auth0.com/v2/logout?returnTo=myapp%3A%2F%2Fcallback");
authTabController.launchUri(logoutUri, false, mockThreadSwitcher, null);

verify(mockAuthTabLauncher, timeout(MAX_TEST_WAIT_TIME_MS)).launch(any(Intent.class));
verify(context, never()).startActivity(any(Intent.class));
}

@Test
public void shouldFallbackToCustomTabWhenAuthTabNotSupportedByBrowser() {
customTabsClientMock = Mockito.mockStatic(CustomTabsClient.class);
Expand Down
Loading