OAuth-based App Flip Linking (App Flip) allows your users to 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 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.
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-based App Flip Flow
The following sequence diagram details the interaction between the User, Google App, Your App, and Your Authorization Server for App Flip.
Roles and responsibilities
The following table defines the roles and responsibilities of the actors in the App Flip flow.
| Actor / Component | GAL Role | Responsibilities |
|---|---|---|
| Google App / Server | OAuth Client | Initiates the linking process, triggers a deep link to your mobile app, exchanges the authorization code for tokens, and securely stores them to access your service's APIs. |
| Your App | Authorization Agent | Authenticates the user (typically using existing app credentials), obtains consent, and retrieves an authorization code from your server. |
| Your Authorization Server | Authorization Server | Validates authorization codes and refresh tokens, and issues access tokens to the Google Server. |
设计准则
本部分介绍了应用翻转账号关联同意屏幕的设计要求和建议。在 Google 调用您的应用后,您的应用会向用户显示同意屏幕。
要求
- 您必须告知用户,其账号将与 Google 关联,而非与 Google Home 或 Google 助理等特定 Google 产品关联。
建议
建议您执行以下操作:
显示 Google 的隐私权政策。在意见征求屏幕上添加指向 Google 隐私权政策的链接。
要分享的数据。使用简洁明了的语言告知用户 Google 需要哪些用户数据以及原因。
明确的号召性用语。在同意屏幕上提供清晰的号召性用语,例如“同意并关联”。这是因为用户需要了解他们必须与 Google 分享哪些数据才能关联其账号。
能够拒绝或取消。如果用户选择不关联,请提供一种供用户返回、拒绝或取消的方式。
能够解除关联。提供一种可供用户取消关联的机制,例如指向您平台上的账号设置的网址。或者,您也可以添加指向 Google 账号的链接,以便用户管理其关联的账号。
能够更改用户账号。建议用户切换账号的方法。如果用户倾向于使用多个账号,此功能尤其有用。
- 如果用户必须关闭同意屏幕才能切换账号,请向 Google 发送可恢复的错误,以便用户可以通过 OAuth 关联和隐式流程登录所需账号。
添加您的徽标。在权限请求页面上显示公司徽标。 根据样式指南放置徽标。如果您还想显示 Google 的徽标,请参阅徽标和商标。
在应用中实现 App Flip
如需实现 App Flip,你需要修改应用中的用户授权代码,以接受来自 Google 的深层链接。
如需在 Android 应用中支持 App Flip,请按照 Android 实现指南中的说明操作。
如需在 iOS 应用中支持 App Flip,请按照 iOS 实现指南中的说明操作。
测试 App Flip
在经过验证的正式版应用和可正常运行的 OAuth 2.0 服务器可用之前,可以使用示例应用和测试应用模拟 App Flip。
在 App Flip 期间,Google 应用会先打开您的应用,然后您的应用会向 OAuth 2.0 服务器请求授权代码响应,最后,响应会返回给 Google 应用。
前提条件
如需模拟 Google 应用并触发启动应用的 intent, 请下载并安装适用于 Android 和 iOS的 App Flip 测试工具。
下载并安装适用于 Android 和 iOS 的 App Flip 示例,以模拟您的应用并选择 OAuth 2.0 响应类型。
测试顺序
- 打开 App Flip 测试工具。
- 按
Try Flip!启动 App Flip 示例应用。 - 从示例应用中的单选按钮中选择一个响应。
- 按
Send将模拟的 OAuth 2.0 响应返回给测试工具。 - 检查测试工具日志消息,了解 auth_code 或错误详情。
生产环境测试
完成 注册和 OAuth 2.0 服务器 实现后,可以在生产环境中测试 App Flip。
建议使用单个 Google 账号和 特定于任务的电子邮件地址 进行自动化测试。
以 Google 账号持有人的身份登录后,可以使用 “关联的账号”查看账号关联状态。您也可以在此处解除账号关联,以便在重复测试之间进行操作。
(可选)您可以选择实现 RISC,以 编程方式解除关联并通知 Google 这一更改。