withAuthTab() fails with HTTPS (App Links) callbacks because CustomTabsController calls the custom-scheme AuthTabIntent.launch() overload

未关闭
#1,130 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin

调研方向

Read CustomTabsController.launchAsAuthTab() and the Auth Tab API usage in LogoutManager; compare how the SDK handles custom-scheme redirects with the documented HTTPS overload. Trace the existing Auth Tab tests and add coverage for HTTPS host and path handling in both login and logout. Done means HTTPS App Links deliver the callback successfully while custom-scheme redirects continue to work.

由索引模型根据 Issue 内容生成。

描述

bug
Checklist
Description

When using WebAuthProvider.login(account).withScheme("https").withAuthTab(), authentication fails to return credentials to the app after the user completes login in the Auth Tab, and instead fails with a0.authentication_canceled ("The user closed the browser app and the authentication was canceled.").

According to examples/auth-tab.md, Auth Tab supports both custom URI schemes and HTTPS (Android App Links) redirects verified through Digital Asset Links.

However, in CustomTabsController.launchAsAuthTab(), the SDK extracts only scheme and unconditionally calls the 3-argument custom-scheme overload of AuthTabIntent.launch():

String scheme = Uri.parse(redirectUri).getScheme();

AuthTabIntent authTabIntent = builder.build();
threadSwitcher.mainThread(() -> authTabIntent.launch(authTabLauncher, uri, scheme));

In androidx.browser:browser:1.10.0, AuthTabIntent has two distinct launch() overloads:

1. launch(launcher, uri, redirectScheme) — sets EXTRA_REDIRECT_SCHEME (must only be used for custom schemes).
2. launch(launcher, uri, redirectHost, redirectPath) — sets EXTRA_HTTPS_REDIRECT_HOST and EXTRA_HTTPS_REDIRECT_PATH (required for https redirects).

Because EXTRA_HTTPS_REDIRECT_HOST and EXTRA_HTTPS_REDIRECT_PATH are never set when scheme is "https", Chrome’s AuthTabIntentDataProvider / AuthTabVerifier does not recognize the HTTPS callback URL as the Auth Tab redirect target:

  1. Chrome’s AuthTabVerifier.isCustomScheme(url) returns false because https is a standard web scheme (UrlUtilities.isAcceptedScheme(url) == true).
  2. Chrome’s AuthTabVerifier.shouldRedirectHttpsAuthUrl(url) returns false because EXTRA_HTTPS_REDIRECT_HOST and EXTRA_HTTPS_REDIRECT_PATH were null.
  3. Instead of finishing the Auth Tab via setResult(RESULT_OK, intent), Chrome falls through to standard Android App Links handling and starts RedirectActivity.
  4. RedirectActivity starts AuthenticationActivity with FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP, which force-finishes the child Auth Tab activity on top of AuthenticationActivity.
  5. Android delivers RESULT_CANCELED to AuthenticationActivity's authTabLauncher before onResume(), causing AuthTabResultHandler to deliver a cancellation result (Intent()) and call finish(), dropping the redirect data from RedirectActivity.

Expected behavior: When the parsed redirectUri has scheme "https", CustomTabsController.launchAsAuthTab() (and LogoutManager when using returnTo) should extract host and path from redirectUri and call the 4-argument overload:

Uri parsedRedirect = Uri.parse(redirectUri);
String scheme = parsedRedirect.getScheme();
if ("https".equalsIgnoreCase(scheme)) {
    String host = parsedRedirect.getHost();
    String path = parsedRedirect.getPath();
    // validate host and path are non-empty, then:
    threadSwitcher.mainThread(() -> authTabIntent.launch(authTabLauncher, uri, host, path));
} else {
    threadSwitcher.mainThread(() -> authTabIntent.launch(authTabLauncher, uri, scheme));
}

Reproduction

Consistently reproducible (100% of attempts):

  1. Configure an Android app with verified HTTPS Android App Links (autoVerify="true" on RedirectActivity, matching assetlinks.json verified on-device via adb shell pm get-app-links).

  2. Start login with Auth Tab and HTTPS scheme:

WebAuthProvider.login(account)
    .withScheme("https")
    .withAuthTab()
    .withEphemeralBrowsing()
    .await(activity)
  1. Complete sign-in on Universal Login inside the Chrome Auth Tab.
  2. Observe that when Auth0 redirects to https:///android//callback?code=..., RedirectActivity is launched instead of authTabLauncher receiving RESULT_OK, and WebAuthProvider throws AuthenticationException with isCanceled == true (a0.authentication_canceled).
Additional context
  • Dependencies: com.auth0.android:auth0:4.3.0, androidx.browser:browser:1.10.0

  • Browser: Chrome 156 (also affects Chrome 137+)

  • Removing .withAuthTab() (using standard Custom Tabs with the exact same HTTPS App Link configuration) succeeds immediately.

  • Also confirmed present on main and v5_development (5.0.0-beta.2).
    Auth0.Android version: 4.3.0 (also affects 4.0.0-beta.1 through 5.0.0-beta.2)

Android version(s): Android 13 (API 33), Samsung SM-G991U (reproduces on any Android 12+ device with Chrome 137+)

Auth0.Android version

4.3.0

Android version(s)

13-17

主要语言
Kotlin
星标
303
派生
182
平均合并
18 小时 42 分钟
30 天内合并 PR
36

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

auth0/Auth0.Android 的其他 Issue

查看 auth0/Auth0.Android 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。