使用 OAuth 的 App Flip 連結 Google 帳戶

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.

設計指南

本節將說明 App Flip 帳戶連結同意畫面的設計規定和建議。Google 呼叫您的應用程式後,應用程式會向使用者顯示同意畫面。

需求條件

  1. 您必須說明使用者的帳戶已連結至 Google,而不是特定 Google 產品 (例如 Google Home 或 Google 助理)。

建議

建議您採取以下做法:

  1. 顯示 Google 的隱私權政策。在同意聲明畫面中加入 Google 隱私權政策的連結。

  2. 要共用的資料。請以清楚簡潔的用語,向使用者說明 Google 需要哪些資料,以及為何需要這些資料。

  3. 明確的行動號召。在同意聲明畫面上明確列出行動號召,例如「同意並連結」。這是因為使用者需要瞭解自己必須與 Google 分享哪些資料,才能連結帳戶。

  4. 可取消訂閱。如果使用者選擇不連結,請提供返回或取消的選項。

  5. 可取消連結。提供使用者解除連結的機制,例如平台上帳戶設定的網址。或者,您也可以加入 Google 帳戶的連結,讓使用者能管理已連結帳戶。

  6. 可變更使用者帳戶。建議使用者切換帳戶的方法。如果使用者傾向擁有多個帳戶,這項功能就特別實用。

    • 如果使用者必須關閉同意畫面才能切換帳戶,請將可復原的錯誤傳送給 Google,方便使用者透過 OAuth 連結隱含流程登入所需帳戶。
  7. 加入標誌。在同意畫面上顯示公司標誌。請依照您的樣式規範放置標誌。如果您也想顯示 Google 的標誌,請參閱標誌和商標

此圖顯示同意畫面範例,其中標示了設計使用者同意畫面時應遵循的個別規定和建議。
圖 2.帳戶連結同意畫面設計指南。

在原生應用程式中實作 App Flip

如要實作 App Flip,您必須修改應用程式中的使用者授權碼,以便接受 Google 提供的深層連結。

如要在 Android 應用程式中支援 App Flip,請按照 Android 實作指南中的指示操作。

如要在 iOS 應用程式中支援 App Flip,請按照 iOS 實作指南中的說明操作。

測試應用程式快速連結

在提供經過驗證的正式版應用程式和正常運作的 OAuth 2.0 伺服器之前,系統可能會使用範例和測試應用程式來模擬 App Flip。

在 App Flip 期間,Google 應用程式會先開啟您的應用程式,然後向 OAuth 2.0 伺服器要求授權碼回應,在最後一個步驟中,系統會將回應傳回 Google 應用程式。

必要條件

如要模擬 Google 應用程式並觸發啟動應用程式的意圖,請下載並安裝 AndroidiOS 適用的 App Flip Test Tool。

下載並安裝適用於 AndroidiOS 的 App Flip 範例,以模擬應用程式並選取 OAuth 2.0 回應類型。

測試序列

  1. 開啟應用程式翻轉測試工具。
  2. 按下 Try Flip! 即可啟動 App Flip 範例應用程式。
  3. 從「Sample」應用程式中的圓形按鈕選取回應。
  4. 按下 Send 即可將模擬的 OAuth 2.0 回應傳回至測試工具。
  5. 請查看測試工具記錄訊息,找出 auth_code 或錯誤詳細資料。

正式版測試

完成註冊程序和 OAuth 2.0 伺服器實作後,您可以在實際工作環境中測試 App Flip。

建議使用單一 Google 帳戶和工作專屬電子郵件地址進行自動化測試。

以 Google 帳戶持有人身分登入後,您可以使用「已連結的帳戶」查看帳戶連結狀態。您也可以在這裡取消連結帳戶,以便重複測試。

您也可以選擇導入 RISC,透過程式碼取消連結,並通知 Google 這項變更。