解除账号关联

解除关联可以从您的平台或 Google 发起,如果在两个平台上显示一致的关联状态,则可以提供最佳用户体验。对于 Google 账号关联,支持令牌撤消端点或跨账号保护功能是可选的。

出现以下任一情况,都可能会解除账号关联:

  • 来自
      用户的请求
    • Google 应用或 Google 账号设置
    • 您的平台
  • 未能续期已过期的刷新令牌
  • 由您或 Google 发起的其他事件。例如,滥用和威胁检测服务中止账号。

用户请求解除与 Google 的关联

通过用户的 Google 账号或应用发起的账号解除关联会删除之前发出的所有访问令牌和刷新令牌,移除用户意见征求,并根据需要调用您的令牌撤消端点(如果您选择实现)。

用户请求与您的平台解除关联

您应为用户提供解除关联的机制,例如指向其账号的网址。如果您不提供解除关联的方法,请添加指向 Google 账号的链接,以便用户管理其关联的账号。

您可以选择实现风险和事故分享与协作 (RISC),并在用户账号关联状态发生变化时通知 Google。这样一来,用户体验会得到提升,您的平台和 Google 都会显示当前一致的关联状态,而无需依赖刷新令牌或访问令牌请求来更新关联状态。

令牌过期

为了提供流畅的用户体验并避免服务中断,Google 会尝试在刷新令牌的生命周期即将结束时续订。在某些情况下,如果没有有效的刷新令牌,则可能需要征得用户同意才能重新关联账号。

将平台设计为支持多个未过期的访问令牌和刷新令牌,可以最大限度地减少分片环境之间客户端-服务器交换中存在的竞态条件,避免用户中断,并最大限度地减少复杂的时间安排和错误处理场景。虽然最终一致,但之前和新发放的未过期令牌都可能会在客户端-服务器令牌续订交换期间和集群同步之前使用很短的时间。例如,在您发出新访问令牌后,Google 会使用之前未过期的访问令牌向您的服务发出请求,但在 Google 收到该令牌并进行集群同步之前。建议采用刷新令牌轮替的替代安全措施。

其他事件

账号可能会由于各种其他原因(例如闲置、暂停、恶意行为等)而解除关联。在这种情况下,您的平台和 Google 可以通过相互通知账号和关联状态的变化,更好地管理用户账号并重新建立关联。

实现一个供 Google 调用的令牌撤消端点,并使用 RISC 通知 Google 您的令牌撤消事件,以确保您的平台和 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)

If you support Cross-Account Protection, your platform can notify Google when access or refresh tokens are revoked. This allows Google to inform users of link state changes, invalidate the token, cleanup security credentials, and authorization grants.

Cross-Account Protection is based on the RISC standard developed at the OpenID Foundation.

A Security Event Token is used to notify Google of token revocation.

When decoded, a token revocation event looks like the following example:

{
  "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"
    }
  }
}

Security Event Tokens that you use to notify Google of token revocation events must conform to the requirements in the following table:

Token revocation events
iss Issuer Claim: This is a URL which you host, and it's shared with Google during registration.
aud Audience Claim: This identifies Google as the JWT recipient. It must be set to google_account_linking.
jti JWT ID Claim: This is a unique ID that you generate for every security event token.
iat Issued At Claim: This is a NumericDate value that represents the time when this security event token was created.
toe Time of Event Claim: This is an optional NumericDate value that represents the time at which the token was revoked.
exp Expiration Time Claim: Do not include this field, as the event resulting in this notification has already taken place.
events
Security Events Claim: This is a JSON object, and must include only a single token revocation event.
subject_type This must be set to oauth_token.
token_type This is the type of token being revoked, either access_token or refresh_token.
token_identifier_alg This is the algorithm used to encode the token, and it must be hash_SHA512_double.
token This is the ID of the revoked token.

For more information on field types and formats, see JSON Web Token (JWT).