【发布时间】:2021-07-21 01:04:35
【问题描述】:
是否可以使用以https:// 开头的Android App Links,例如:https://my-app.com/callback 在OAuth2 流程结束时从Android WebView 重定向回我的应用程序?我知道正常的深层链接是如何工作的,例如 com.my-app:// 或 my-app:// 可用于重定向回我的应用程序。根据我的理解,如果AndroidManifest.xml 中提供了足够的 IntentFilter,WebView 不知道如何处理此类协议,将请求传递给操作系统,然后操作系统将请求传递给我处理此 url 的应用程序。
这可以通过https:// 方案来完成,否则重定向将始终被 WebView 捕获并且无法重定向回我的应用程序?
指定我想通过步骤实现的目标:
-
AndroidManifest.xml中提供了一个 IntentFilter 来处理应用链接,例如:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="my-app.com/callback" />
<data android:scheme="https" />
</intent-filter>
-
https://my-app.com/.well-known/assetlinks.json提供了有效的assetlinks.json(此时,IntentFilterIntent日志显示 JSON 验证成功,我可以使用类似npx uri-scheme open https://my-app.com/callback的命令从终端打开应用程序) - 我的应用程序通过启动
CustomTabsIntent.launchUrl来启动 OAuth2 流程,其 url 如下:
https://accounts.google.com/o/oauth2/v2/auth?
scope=email%20profile&
response_type=code&
state=state&
redirect_uri=https://my-app.com/callback&
client_id=client_id
完成这些步骤后,我希望我的应用程序在成功登录后打开,因为它是 url 的有效处理程序,并且不希望卡在浏览器中。这可能吗,或者请求永远不会从浏览器转发到操作系统,因为浏览器是https:// 方案的有效处理程序?
如果上述方法是不可能的,有没有办法从 WebView 导航回 App,提供 auth_code 或唯一的方法是使用自定义方案?
【问题讨论】:
标签: android oauth-2.0 deep-linking applinks android-app-links