解除关联操作可能由您的平台或 Google 发起,在两个平台上显示一致的关联状态可提供最佳用户体验。对于 Google 账号关联,支持令牌撤消端点或跨账号保护是可选的。
账号可能会因以下任何原因而取消关联:
- 用户请求来自
- Google 应用或 Google 账号设置
- 您的平台
- 无法续订已过期的刷新令牌
- 您或 Google 发起的其他活动。例如,滥用行为和威胁检测服务暂停账号。
用户请求取消与 Google 的关联
通过用户的 Google 账号或应用发起的账号解除关联操作会删除之前签发的任何访问令牌和刷新令牌,移除用户同意,并根据您的选择调用令牌撤消端点(如果您选择实现该端点)。
用户请求取消与您的平台的关联
您应为用户提供一种取消关联的机制,例如指向其账号的网址。如果您未提供供用户解除关联的方式,请添加指向 Google 账号的链接,以便用户管理其关联的账号。
您可以选择实施风险和事件共享与协作 (RISC),并通知 Google 用户账号关联状态的变更。这样一来,您的平台和 Google 都可以显示当前一致的关联状态,而无需依赖刷新或访问令牌请求来更新关联状态,从而改善用户体验。
令牌过期
为了提供顺畅的用户体验并避免服务中断,Google 会尝试在刷新令牌即将过期时续订。在某些情况下,如果无法获取有效的刷新令牌,可能需要用户同意才能重新关联账号。
将平台设计为支持多个未过期的访问令牌和刷新令牌,可以最大限度地减少集群环境中客户端-服务器交换存在的竞态条件,避免用户中断,并最大限度地减少复杂的时序和错误处理场景。虽然最终会保持一致,但在客户端-服务器令牌续订交换期间以及集群同步之前,之前和新签发的未过期令牌可能会在短时间内同时使用。例如,在您发出新的访问令牌后,但在 Google 收到该令牌并进行集群同步之前,Google 向您的服务发出的请求使用了之前的未过期访问令牌。建议采用 Refresh Token Rotation 的替代安全措施。
其他事件
账号可能会因各种其他原因(例如不活跃、被中止、恶意行为等)而被解除关联。在这种情况下,您的平台和 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)
如果您支持跨账号保护功能,您的平台可以在以下情况下通知 Google: 访问或刷新令牌会被撤消。这样,Google 就可以告知用户 更改关联状态、使令牌失效、清理安全凭据 授权。
跨账号保护以 RISC 标准是 OpenID Foundation。
安全事件令牌 用于通知 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 |
Issuer Claim:这是由您托管的网址,并且会分享给 在注册过程中与 Google 联系。 | ||||||||||
aud |
受众群体声明:这可将 Google 标识为 JWT 收件人。它
必须设置为 google_account_linking。 |
||||||||||
jti |
JWT ID 声明:这是您为每次 JWT 生成的唯一 ID 安全事件令牌 | ||||||||||
iat |
Issued At Claim:这是一个 NumericDate 值
表示创建此安全性事件令牌的时间。 |
||||||||||
toe |
事件声明时间:此为可选
NumericDate 值,该值表示
已撤消。 |
||||||||||
exp |
到期时间声明:请勿包含此字段。 因为导致此通知的事件已经发生。 | ||||||||||
events |
|
||||||||||
如需详细了解字段类型和格式,请参阅 JSON 网络令牌 (JWT)。