概览

OAuth-based App Flip Linking (App Flip) allows your users to easily and quickly link their accounts in your authentication system to their Google accounts. If your app is installed on your user’s phone when they initiate the account linking process, they are seamlessly flipped to your app to obtain user authorization.

This approach provides a faster and easier linking process since the user does not have to re-enter their username and password to authenticate; instead, App Flip leverages the credentials from the user's account on your app. Once a user has linked their Google account with your app, they can take advantage of any integrations that you have developed.

You can set up App Flip for both iOS and Android apps.

This figure shows the steps for a user to link their Google account
            to your authentication system. The first screenshot shows how a user
            can select your app if their Google account is linked to your app.
            The second screenshot shows the confirmation for linking their
            Google account with your app. The third screenshot shows a
            successfully linked user account in the Google app.
Figure 1. Account linking on a user's phone with App Flip.

Requirements

To implement App Flip, you must fulfill the following requirements:

  • You must have an Android or iOS app.
  • You must own, manage and maintain an OAuth 2.0 server which supports the OAuth 2.0 authorization code flow.

如需详细了解 OAuth 关联授权代码流程,请参阅实现 OAuth 服务器

设计准则

本部分介绍了应用快速关联帐号关联同意屏幕的设计要求和建议。Google 调用您的应用后,应用会向用户显示同意屏幕。

要求

  1. 您必须告知用户用户帐号正在与 Google 关联,而不是与特定 Google 产品(例如 Google Home 或 Google 助理)关联。

建议

建议您执行以下操作:

  1. 显示 Google 的隐私权政策。在同意屏幕上添加指向 Google 隐私权政策的链接。

  2. 要共享的数据。使用简洁明了的语言向用户说明他们的 Google 需要哪些数据以及为何收集这些数据。

  3. 明确的号召性用语。在同意屏幕上提供明确的号召性用语,例如“同意并关联”。这是因为用户需要了解他们需要与 Google 共享哪些数据,才能关联帐号。

  4. 能够取消。如果用户不关联,则可以提供返回或取消的方式。

  5. 能够解除关联。为用户提供解除关联的机制,例如他们在平台上的帐号设置网址。或者,您也可以添加指向 Google 帐号的链接,以便用户可以管理关联的帐号。

  6. 能够更改用户帐号。推荐一种供用户切换帐号的方法。如果用户往往拥有多个帐号,这一点尤其有用。

    • 如果用户必须关闭同意屏幕才能切换帐号,请向 Google 发送一个可恢复错误,以便用户通过 OAuth 关联隐式流程登录所需帐号。
  7. 添加徽标。在同意屏幕上显示公司徽标。 根据样式指南放置徽标。如果您还希望显示 Google 的徽标,请参阅徽标和商标

下图所示为同意屏幕的示例,其中展示了在设计用户同意屏幕时要遵循的各项要求和建议。
图 2.帐号关联同意屏幕设计准则。

基于 OAuth 的应用快速关联的设置

以下部分描述了基于 OAuth 的应用快速关联的前提条件,以及如何在 Actions 控制台中配置应用快速关联项目。

创建 Action 并设置 OAuth 2.0 服务器

如需配置应用快速关联,你需要先执行以下操作:

  • 创建 Action。如需创建 Action,请按照创建项目部分中的说明操作。
  • 设置 OAuth 2.0 服务器。如需详细了解如何设置 OAuth 服务器,请参阅实现 OAuth 帐号关联

在 Actions 控制台中配置应用快速关联

以下部分介绍了如何在 Actions 控制台中配置应用快速关联。

  1. 点击顶部导航栏中的 Develop。然后,点击左侧导航栏中的 Account linking
  2. 开启帐号关联旁边的开关。
  3. 帐号创建下,选择不,我只想允许在我的网站上创建帐号
  4. 点击下一步
  5. 关联类型下,从下拉菜单中选择 OAuth授权代码
  6. 点击 Next
  7. 填写 OAuth Client information 下的所有字段。(如果不支持 App Flip,则会使用常规 OAuth 作为后备选项。)
  8. 点击下一步
  9. Use your app for account linking (optional) 下方,选中 Enable for iOS
  10. 填写 Universal Link 字段。如需详细了解通用链接,请参阅允许应用和网站链接到您的内容
  11. 如果您想视情况配置客户端,请添加范围,然后点击 Configure your client (optional) 下的 Add scope。 如果没有,请点击下一步
  12. 在“测试说明”下,输入 test(或任何其他字符串)作为占位符。(只有在您实际提交要发布的 Action 时,才需要使用测试账号填写此字段。)
  13. 点击保存

现在,你可以继续阅读下一部分,了解如何在 iOS 或 Android 应用中实现应用快速关联功能。

在原生应用中实现应用快速关联

如需实现应用快速关联功能,你需要修改应用中的用户授权代码,以接受来自 Google 的深层链接。

在设备上测试应用快速关联

现在,你已在控制台和应用中创建了一个 Action 并配置了应用快速关联,接下来可以在移动设备上测试应用快速关联。你可以使用 Google 助理应用测试 App Flip。

如需从 Google 助理应用测试应用快速关联,请按以下步骤操作:

  1. 转到 Actions 控制台,然后选择你的项目。
  2. 点击顶部导航栏中的 Test
  3. 在 Google 助理应用中触发账号关联流程:
    1. 打开 Google 助理应用
    2. 点击设置
    3. 在“Google 助理”标签页上,点击家居控制
    4. 点击“添加”(+)
    5. 从提供商列表中选择你的 Action。它在列表中以“[test]”为前缀。从列表中选择 [test] Action 后,就应该会打开你的应用。
    6. 验证你的应用是否已启动并开始测试授权流程。