選擇整合路徑
請選取最符合需求的途徑:
| 路徑 | 適用情境 | 瞭解詳情 |
|---|---|---|
| 通用商務通訊協定 (UCP) | 商家和零售商。 | UCP 文件 |
| 標準帳戶連結 | 智慧型住宅、電視和 YouTube。 | 文件 |
帳戶連結功能可讓 Google 帳戶持有人快速、順暢且安全地連結至您的服務。您可以選擇實作 Google 帳戶連結,將平台上的使用者資料分享給 Google 應用程式和服務。
安全的 OAuth 2.0 通訊協定可讓您安全地將使用者的 Google 帳戶連結至平台帳戶,進而授予 Google 應用程式和裝置服務存取權。
使用者可以連結或取消連結帳戶,也可以選擇在您的平台上透過 Google 帳戶連結功能建立新帳戶。
用途
實作 Google 帳戶連結的原因包括:
與 Google 應用程式和服務共用平台上的使用者資料。
使用通用商務通訊協定 (UCP),與 Google 購物和 AI 平台 (搜尋、Gemini) 整合。
使用 Google TV 播放影片和電影內容。
使用 Google Home 應用程式和 Google 助理管理及控制Google 智慧住宅連結裝置,例如說出「Ok Google,開燈」。
透過對話動作建立使用者自訂的 Google 助理體驗和功能,例如「Ok Google,幫我向星巴克訂購平常的餐點」。
使用者將 Google 帳戶連結至獎勵合作夥伴帳戶後,只要在 YouTube 觀看符合資格的直播,就有機會獲得獎勵。
在註冊期間,使用Google 帳戶個人資料中經同意分享的資料,預先填入新帳戶。
支援的功能
Google 帳戶連結功能支援下列功能:
使用 OAuth 連結隱含流程快速分享資料。
使用 OAuth 連結授權碼流程,提供更完善的安全性。
讓現有使用者登入平台,或讓新的 Google 驗證使用者註冊平台,取得他們的同意聲明,並透過簡化連結安全地分享資料。
使用應用程式切換功能減少摩擦。在可信任的 Google 應用程式中,輕觸一下即可安全開啟已驗證的 Android 或 iOS 應用程式,輕觸一下即可授予使用者同意聲明並連結帳戶。
定義自訂範圍,只分享必要資料,提升使用者隱私權;清楚定義資料使用方式,提高使用者信任感。
如要撤銷存取權,請取消連結帳戶。實作選用的權杖撤銷端點,可讓您與 Google 啟動的事件保持同步,而跨帳戶保護(RISC) 則可讓您將平台上的任何取消連結事件通知 Google。
帳戶連結流程
Google 帳戶連結流程共有 3 種,全都是以 OAuth 為基礎,因此您必須管理或控管符合 OAuth 2.0 規範的授權和權杖交換端點。
在連結程序中,您必須先取得帳戶擁有者的同意,才能連結帳戶及共用資料,然後再為個別 Google 帳戶向 Google 核發存取權杖。
OAuth 連結 (「網頁 OAuth」)
這是基本 OAuth 流程,可將使用者導向網站進行連結。系統會將使用者重新導向至您的網站,讓他們登入帳戶。登入後,使用者會同意將服務中的資料分享給 Google。此時,使用者的 Google 帳戶和您的服務會連結在一起。
OAuth 連結支援授權碼和隱含 OAuth 流程。您的服務必須代管符合 OAuth 2.0 規範的授權端點,以供隱含流程使用,並在使用授權碼流程時,公開授權和權杖交換端點。
圖 1. 在使用者手機上透過 Web OAuth 連結帳戶
以 OAuth 為基礎的應用程式快速連結 (「應用程式快速連結」)
OAuth 流程,可將使用者帶往您的應用程式進行連結。
以 OAuth 為基礎的應用程式切換連結功能會引導使用者在已驗證的 Android 或 iOS 行動應用程式與 Google 平台之間切換,查看建議的資料存取權變更,並同意將平台上的帳戶連結至 Google 帳戶。如要啟用應用程式切換功能,服務必須支援使用授權碼流程的 OAuth 連結或 OAuth 型「使用 Google 帳戶登入」連結。
運作方式:
Google 應用程式會檢查使用者裝置是否已安裝您的應用程式:
- 如果找到應用程式,系統會「翻轉」至您的應用程式。您的應用程式會徵求使用者同意將帳戶連結至 Google,然後「翻轉回」Google 介面。
- 如果找不到應用程式,或在應用程式快速連結的連結過程中發生錯誤,系統會將使用者重新導向至簡化或網頁 OAuth 流程。
圖 2. 在使用者手機上透過應用程式切換功能連結帳戶
以 OAuth 為基礎的簡化連結 (「簡化」)
以 OAuth 為基礎的「使用 Google 帳戶登入」簡化連結功能,會在 OAuth 連結的基礎上新增「使用 Google 帳戶登入」功能,讓使用者不必離開 Google 服務即可完成連結程序,減少阻礙和流失。以 OAuth 為基礎的簡化連結
結合「使用 Google 帳戶登入」和 OAuth 連結功能,提供最優質的使用者體驗,讓使用者順暢登入、建立及連結帳戶。您的服務必須支援符合 OAuth 2.0 規範的授權和權杖交換端點。此外,權杖交換端點必須支援 JSON Web Token (JWT) 斷言,並實作 check、create 和 get 意圖。
運作方式:
Google 會驗證使用者帳戶,並將這項資訊傳遞給您:
- 如果資料庫中已有該使用者的帳戶,使用者就能順利將 Google 帳戶連結至服務中的帳戶。
- 如果資料庫中沒有使用者的帳戶,使用者可以選擇使用 Google 提供的聲明資訊 (電子郵件地址、姓名和個人資料相片) 建立新的第三方帳戶,也可以選擇登入並連結至其他電子郵件地址 (這會要求他們使用 Web OAuth 登入您的服務)。
圖 3. 在使用者手機上透過簡化連結功能連結帳戶
您應該使用哪個流程?
建議您導入所有流程,確保使用者享有最佳連結體驗。簡化和應用程式快速連結流程可減少連結阻力,因為使用者只需幾個步驟即可完成連結過程。網頁 OAuth 連結的作業量最少,建議您先從這個流程著手,之後再新增其他連結流程。
使用權杖
Google 帳戶連結功能是以 OAuth 2.0 業界標準為基礎。
取得帳戶擁有者同意連結帳戶及共用資料後,您即可為個別 Google 帳戶向 Google 發行存取權杖。
Token types
OAuth 2.0 uses strings called tokens to communicate between the user agent, the client application, and the OAuth 2.0 server.
Three types of OAuth 2.0 tokens can be used during account linking:
Authorization code. A short-lived token that can be exchanged for an access and a refresh token. For security purposes, Google calls your authorization endpoint to obtain a single use or very short-lived code.
Access token. A token that grants the bearer access to a resource. To limit exposure that could result from the loss of this token, it has a limited lifetime, usually expiring after an hour or so.
Refresh token. A long-lived token that can be exchanged for a new access token when an access token expires. When your service integrates with Google, this token is exclusively stored and used by Google. Google calls your token exchange endpoint to exchange refresh tokens for access tokens, which are in turn used to access user data.
Token handling
Race conditions in clustered environments and client-server exchanges can result in complex timing and error handling scenarios when working with tokens. For example:
- You receive a request for a new access token, and you issue a new access token. Concurrently, you receive a request for access to your service's resource using the previous, unexpired access token.
- Your refresh token reply is yet to be received (or is never received) by Google. Meanwhile, the previously valid refresh token is used in a request from Google.
Requests and replies can arrive in any order, or not at all due to asynchronous services running in a cluster, network behavior, or other means.
Immediate and fully consistent shared state both within, and between, your and Google's token handling systems cannot be guaranteed. Multiple valid, unexpired tokens can coexist within or across systems short period of time. To minimize negative user impact we recommend you do the following:
- Accept unexpired access tokens, even after a newer token is issued.
- Use alternatives to Refresh Token Rotation.
- Support multiple, concurrently valid access and refresh tokens. For security, you should limit the number of tokens and token lifetime.
Maintenance and outage handling
During maintenance or unplanned outages Google might be unable to call your authorization or token exchange endpoints to obtain access and refresh tokens.
Your endpoints should respond with a 503 error code and empty body. In this
case, Google retries failed token exchange requests for a limited time. Provided
that Google is later able to obtain refresh and access tokens, failed requests
are not visible to users.
Failing requests for an access token result in a visible error, if initiated by a user. Users will be required to retry linking failures if the implicit OAuth 2.0 flow is used.
Recommendations
There are many solutions to minimize maintenance impact. Some options to consider:
Maintain your existing service and route a limited number of requests to your newly updated service. Migrate all requests only after confirming expected functionality.
Reduce the number of token requests during the maintenance period:
Limit maintenance periods to less than the access token lifetime.
Temporarily increase the access token lifetime:
- Increase token lifetime to greater than maintenance period.
- Wait twice the duration of your access token lifetime, enabling users to exchange short lived tokens for longer duration tokens.
- Enter maintenance.
- Respond to token requests with a
503error code and empty body. - Exit maintenance.
- Decrease token lifetime back to normal.
使用 Google 帳戶註冊
我們需要 OAuth 2.0 設定的詳細資料,並分享憑證來啟用帳戶連結。詳情請參閱註冊。