Cómo desvincular cuentas

La desvinculación se puede iniciar desde tu plataforma o Google, y la visualización de un estado de vínculo coherente en ambas proporciona la mejor experiencia del usuario. La compatibilidad con un extremo de revocación de tokens o la Protección integral de la cuenta es opcional para la vinculación de Cuentas de Google.

Las cuentas se pueden desvincular por cualquiera de los siguientes motivos:

  • Solicitud del usuario desde
  • No se pudo renovar un token de actualización vencido.
  • Otros eventos iniciados por ti o Google. Por ejemplo, la suspensión de la cuenta por servicios de detección de amenazas y abusos.

El usuario solicitó la desvinculación de Google

La desvinculación de la cuenta que se inicia a través de la Cuenta de Google o la app de un usuario borra todos los tokens de acceso y actualización emitidos anteriormente, quita el consentimiento del usuario y, de manera opcional, llama a tu extremo de revocación de tokens si decidiste implementar uno.

El usuario solicitó la desvinculación de tu plataforma

Debes proporcionar un mecanismo para que los usuarios se desvinculen, como una URL a su cuenta. Si no ofreces una forma para que los usuarios se desvinculen, incluye un vínculo a la Cuenta de Google para que los usuarios puedan administrar su cuenta vinculada.

Puedes optar por implementar el uso compartido y la colaboración de riesgos y incidentes (RISC) y notificar a Google los cambios en el estado de vinculación de la cuenta de los usuarios. Esto permite una experiencia del usuario mejorada en la que tanto tu plataforma como Google muestran un estado de vinculación actual y coherente sin necesidad de depender de una solicitud de token de actualización o token de acceso para actualizar el estado de vinculación.

Vencimiento del token

Para proporcionar una experiencia del usuario fluida y evitar la interrupción del servicio, Google intenta renovar los tokens de actualización cerca del final de su ciclo de vida. En algunas situaciones, es posible que se requiera el consentimiento del usuario para volver a vincular las cuentas cuando no haya un token de actualización válido disponible.

Diseñar tu plataforma para que admita varios tokens de acceso y actualización no vencidos puede minimizar las condiciones de carrera presentes en los intercambios cliente-servidor entre entornos agrupados, evitar la interrupción del usuario y minimizar los escenarios complejos de manejo de errores y sincronización. Si bien es coherente, es posible que se usen tokens no vencidos anteriores y recién emitidos durante un breve período durante el intercambio de renovación de tokens cliente-servidor y antes de la sincronización del clúster. Por ejemplo, una solicitud de Google a tu servicio que usa el token de acceso no vencido anterior ocurre justo después de que emites un token de acceso nuevo, pero antes de que se realice la recepción y la sincronización del clúster en Google. Se recomiendan medidas de seguridad alternativas a la rotación de tokens de actualización.

Otros eventos

Las cuentas se pueden desvincular por varios motivos, como inactividad, suspensión, comportamiento malicioso, etcétera. En estos casos, tu plataforma y Google pueden administrar mejor las cuentas de usuario y volver a vincularlas notificándose mutuamente los cambios en el estado de la cuenta y el vínculo.

Implementa un extremo de revocación de tokens para que Google lo llame y notifica a Google tus eventos de revocación de tokens con RISC para garantizar que tu plataforma y Google mantengan un estado de vínculo de cuenta de usuario coherente.

Extremo de revocación de tokens

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.

Protección integral de la cuenta (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).