我想捕获 Chrome 自定义选项卡中发生的重定向,以确保用户停留在本机移动应用程序中。
Chrome 自定义选项卡的启动方式如下:
val url = "https://demo.company.com/sso/oidc/start/?idp_connection_id=Username-Password-Authentication&status_response_url=https://member.example.com/urgent"
val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(this, Uri.parse(url))
用户进行身份验证后,该网页将重定向到作为
status_response_url
参数给出的 URL。移动应用程序注册适当的方案:
<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:host="member.example.com"
android:scheme="https" />
</intent-filter>
不幸的是,系统似乎没有捕获重定向。为什么?
这是应用程序链接和 SSO 的一个众所周知的问题,因为缺少 用户手势。
您正在使用首选声明的 HTTPS 方案选项,但需要一个插页式网页才能可靠地工作。
我的博客文章有关于此的更多信息,包括您可以运行以查看用户体验的代码示例。
@Gary Archer 描述了应用程序链接和 SSO 的众所周知的问题。
我想在AppAuth示例中添加它(工作正常)https://github.com/skiph/AppAuth-Android/blob/619e9b0f6d27fd393a8332ceb324d8d243082251/app/java/net/openid/appauthdemo/LoginActivity.java#L457他们有
warmUpBrowser
功能来解决这个问题。
如果您在“登录”按钮处理程序中创建浏览器意图,则不会捕获 chrome 选项卡中的重定向(因为浏览器不接收交互)。这就是为什么他们提前创建浏览器意图,从而捕获一些交互并在意图中接收重定向。
我花了几天时间才明白他们为什么这样做。