取消帳戶連結

透過平台或 Google 可能會取消連結,並顯示一致的連結狀態以提供最佳使用者體驗。雖然 Google 帳戶連結不支援憑證撤銷端點或跨帳戶防護功能,

您可以透過下列方式取消連結帳戶:

  • 使用者向
  • 無法更新過期的更新權杖
  • 您或 Google 發起的其他事件。例如濫用與威脅偵測服務將帳戶停權。

使用者要求與 Google 取消連結

透過使用者 Google 帳戶或應用程式取消連結的帳戶,會刪除先前核發的所有存取權和更新權杖、移除使用者同意聲明,並視需要選擇呼叫權杖撤銷端點。

使用者要求與平台取消連結

您應提供讓使用者取消連結的機制,例如帳戶的網址。如果您未提供使用者取消連結的方式,請加入 Google 帳戶連結,方便使用者管理已連結帳戶。

您可以選擇導入 Risk & Eventident and Collaborative (RISC),然後通知 Google 使用者帳戶連結狀態的變更。如此一來,平台和 Google 就能顯示一致的一致連結狀態,不需要依賴重新整理或存取權杖要求來更新連結狀態,進而改善使用者體驗。

權杖到期時間

為了提供順暢的使用者體驗,並避免服務中斷,Google 會嘗試在生命週期結束時更新續約權杖。在某些情境下,如果使用者的有效重新整理權杖無效,系統可能會要求使用者重新連結帳戶。

將平台設計為支援多個未過期的存取和更新權杖,可以盡可能降低叢集環境中用戶端伺服器交換作業中的競爭狀況、避免使用者中斷的情況,並將複雜的時間與錯誤處理情境降到最低。雖然最終一致,但先前和新核發的未過期權杖在用戶端與伺服器權杖更新交換期間以及叢集同步處理之前,可能會短暫使用一段時間。舉例來說,向使用先前未過期存取權杖之服務向 Google 發出的要求,會在您發出新的存取權杖後執行,但鄰近的接收位置和叢集同步處理才會在 Google 完成。建議您改用重新整理權杖輪替的其他安全性措施。

其他事件

可能會因為各種其他因素 (例如閒置、暫停、惡意行為等) 而取消連結帳戶。在這類情況下,您的平台和 Google 可以最佳通知使用者帳戶和連結狀態的異動,進而管理使用者帳戶並重新連結。

實作權杖撤銷端點,以便 Google 呼叫服務,並使用 RISC 通知權杖權杖撤銷事件,以確保您的平台和 Google 能維持一致的使用者帳戶連結狀態。

權杖撤銷端點

If you support an OAuth 2.0 token revocation endpoint, your platform can receive notifications from Google. This lets you inform users of link state changes, invalidate a token, and cleanup security credentials and authorization grants.

The request has the following form:

POST /revoke HTTP/1.1
Host: oauth2.example.com
Content-Type: application/x-www-form-urlencoded

client_id=GOOGLE_CLIENT_ID&client_secret=GOOGLE_CLIENT_SECRET&token=TOKEN&token_type_hint=refresh_token

Your token revocation endpoint must be able to handle the following parameters:

Revocation endpoint parameters
client_id A string that identifies the request origin as Google. This string must be registered within your system as Google's unique identifier.
client_secret A secret string that you registered with Google for your service.
token The token to be revoked.
token_type_hint (Optional) The type of token being revoked, either an access_token or refresh_token. If unspecified, defaults to access_token.

Return a response when the token is deleted or invalid. See the following for an example:

HTTP/1.1 200 Success
Content-Type: application/json;charset=UTF-8

If the token can't be deleted for any reason, return a 503 response code, as shown in the following example:

HTTP/1.1 503 Service Unavailable
Content-Type: application/json;charset=UTF-8
Retry-After: HTTP-date / delay-seconds

Google retries the request later or as requested by Retry-After.

跨帳戶防護功能 (RISC)

如果您支援跨帳戶防護,存取權或重新整理權杖遭到撤銷時,您的平台可以通知 Google。這可讓 Google 通知使用者連結狀態變更、撤銷權杖、清除安全性憑證及授權。

跨帳戶防護是以 OpenID Foundation 開發的 RISC 標準為基礎。

安全性事件權杖的用途是將權杖撤銷通知 Google。

解碼時,權杖撤銷事件看起來會像這樣:

{
  "iss":"http://risc.example.com",
  "iat":1521068887,
  "aud":"google_account_linking",
  "jti":"101942095",
  "toe": "1508184602",
  "events": {
    "https://schemas.openid.net/secevent/oauth/event-type/token-revoked":{
      "subject_type": "oauth_token",
      "token_type": "refresh_token",
      "token_identifier_alg": "hash_SHA512_double",
      "token": "double SHA-512 hash value of token"
    }
  }
}

您用來向 Google 通知權杖撤銷事件的安全性事件權杖必須符合下表中的規定:

權杖撤銷事件
iss 核發者聲明:這是由你代管的網址,會在註冊期間提供給 Google。
aud 目標對象聲明:將 Google 視為 JWT 的接收者。這個欄位必須設為 google_account_linking
jti JWT ID 憑證附加資訊:這是您為每個安全性事件憑證產生的專屬 ID。
iat 發出時間:這是 NumericDate 值,表示這個安全性事件權杖的建立時間。
toe 事件宣告時間:這是「選填」的 NumericDate 值,代表權杖撤銷的時間。
exp 到期時間:「請勿」加入這個欄位,因為導致這則通知的發生事件已經發生。
events
安全性事件聲明:此為 JSON 物件,且只能包含單一權杖撤銷事件。
subject_type 這個欄位必須設為 oauth_token
token_type 這是要撤銷的憑證類型,可能是 access_tokenrefresh_token
token_identifier_alg 這是用於編碼權杖的演算法,必須採用 hash_SHA512_double
token 這是已撤銷權杖的 ID。

如要進一步瞭解欄位類型和格式,請參閱 JSON Web Token (JWT)