如何使用 Google 应用程序操作设置身份验证

How to setup Authentication with Google App Actions

查看有关身份验证的应用程序操作切片实现信息。 Google 有来自 https://developers.google.com/actions/appactions/slices#handling_authentication 的这些行:

  • (Required) Where user authentication is needed to complete a user flow, return a Slice that explains that the user needs to continue in the app. In-line user authentication in the Assistant is not supported for App Actions.

  • If users are permitting your app to show data via Slices, you can return an Error Slice at runtime for unauthorized users.

但是,我找不到任何关于在哪里可以找到启动助手功能的身份验证的参考资料。这是在切片提供程序中提供的,还是在调用您的应用程序之前由助手自动为帐户处理的?有一个在切片中提供您的帐户信息的用例,您需要以某种方式对助理请求进行身份验证,无论是来自助理的东西说语音与设备上的现有用户匹配,还是与您拥有的其他类型的帐户信息相匹配设备。

App Actions 有两种实现模式(通过深度 link 或通过 Slice)。在这两种情况下,当 Assistant 请求 App Action 时运行的代码都在你的应用程序中(deep link 通过你的 Activity 和 Slices 通过你的 SliceProvider)。

这意味着您自己的代码可以检查用户是否已登录您的应用并做出相应的响应。

  • 对于深度 link 实现,您的活动之一将打开,您可以将用户重定向到您的主登录屏幕

  • 对于切片,在您的 SliceProvider 中,您可以检查用户是否已登录,如果没有,return 返回一个切片,其中包含解释用户需要登录的文本通过您的应用程序登录以查看内容。 Assistant 中显示的切片在页脚中也自动有一个 "Open app" 按钮,因此用户可以直接打开您的应用程序以通过常规应用程序登录流程登录(您也可以在正文中添加自己的 link可以将用户带到登录屏幕的切片,由您决定。

所以基本上,应用操作的授权检查和授权流程完全发生在您的 Android 应用代码中。在此阶段,应用程序操作助手中没有身份验证流程或 API,这是文档在说时所指的内容:

In-line user authentication in the Assistant is not supported for App Actions.