【问题标题】:Deep Link - Https unexpectedly redirecting to chrome深度链接 - Https 意外重定向到 chrome
【发布时间】:2020-07-14 09:28:10
【问题描述】:

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

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

这是开始 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 浏览器时(最初在模拟器中打开网页时),这是否基本上覆盖了我的深层链接?那可能吗?也不可能使用不同的方案,因为 Trello 强制使用 https/http 作为受信任的重定向/回调 url?

【问题讨论】:

    标签: android kotlin oauth deep-linking


    【解决方案1】:

    这与我对 deeplinks vs AppLinks 的误解有关。我想将其更多地视为 AppLink 与深度链接,这意味着已经验证该 URL 属于我的应用程序(通过我域上的文件)。要进行此验证,我需要相应 url 上的验证文件,如果它不存在 - 验证不会发生。每个主机/方案都会发生这种情况,并且必须验证所有匹配。

    解决方案是删除与应用程序/域无关的方案/主机,以允许自动验证。

    “只有当系统为清单中的所有主机找到匹配的数字资产链接文件时,它才会将您的应用程序建立为指定 URL 模式的默认处理程序。” 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      相关资源
      最近更新 更多