Deep Link - Https 意外重定向到 chrome

Deep Link - Https unexpectedly redirecting to chrome

我正在努力将 OAuth 流程添加到我的应用程序中的 Trello 集成中。这个想法是使用深度 linking 在应用程序本身内使用响应(应用程序和数据库之间没有服务器 - 我正在使用空间)。

到目前为止,除了回调重定向部分外,我已经完成了所有工作,并且它可以在我的真实设备上运行,而不是在模拟器上运行。

这是开始 OAuth 流程的代码。

val connection = object:CustomTabsServiceConnection() {
        override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
            val builder = CustomTabsIntent.Builder()
            val customTabsIntent = builder.build()
            client.warmup(0)
            var authUrl = "$TOKEN_URL?key=$API_KEY&scope=read&callback_method=fragment&return_url=${AuthenticationManager.HTTPS_REDIRECT_URL}&expiration=never&name=$NAME&integration=${integration.id}"
            customTabsIntent.launchUrl(context, Uri.parse(authUrl))
        }
        override fun onServiceDisconnected(name: ComponentName?) {
        }
    }
    bindCustomTabsService(context, "com.android.chrome", connection);

清单

 <activity
            android:name="com.myapp.MainActivity"
            android:screenOrientation="sensor"
            android:windowSoftInputMode="adjustPan"
            android:launchMode="singleTop"
            android:configChanges="uiMode">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="pomodoro" android:host="oauth.myapp.com"/>
            <data android:scheme="https" android:host="myapp.com"/>
        </intent-filter>
    </activity>

此时它被重定向到我的网页,我在我的真实设备上验证了它重定向到我的应用程序(因此它可以使用意图并获得必要的令牌)。我想知道当我选择始终用于 chrome 浏览器时(当最初在模拟器中打开网页时),这是否基本上覆盖了我的深度 link?那可能吗?使用不同的方案也是不可能的,因为 Trello 强制使用 https/http 作为受信任的 redirect/callback urls?

这与我对深度链接与应用链接的误解有关。我想将其更多地视为 AppLink 与深层链接,这意味着已经验证此 URL 属于我的应用程序(通过我域中的文件)。要进行此验证,我需要适当的 url 处的验证文件,如果不存在 - 无法进行验证。每个 host/scheme 都会发生这种情况,并且必须验证所有匹配项。

解决方案是删除与 app/domain 无关的 scheme/host,以允许自动验证。

"Only if the system finds a matching Digital Asset Links file for all hosts in the manifest does it then establish your app as the default handler for the specified URL patterns." https://developer.android.com/training/app-links/verify-site-associations

将我的清单更新到下面后,它按预期工作,并按预期重定向了 OAuth 流程。

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="https" android:host="myapp.com"/>
        </intent-filter>