Overview

  • Account linking securely connects a user's Google Account to their account on your platform using the OAuth 2.0 protocol, allowing Google apps and services to access data and services you host with user consent.

  • Google Account Linking can be used for various purposes, including sharing user data with Google apps, enabling features like Google TV and Smart Home integration, creating custom Google Assistant experiences, and streamlining account creation during sign-up.

  • There are three primary OAuth-based flows for Google Account Linking: Web OAuth (redirects to your website), App Flip (switches to your mobile app), and Streamlined Linking (completes the process within the Google surface).

  • Implementing the Web OAuth flow is required as a fallback for all account linking integrations.

  • Google Account Linking utilizes standard OAuth 2.0 token types (authorization code, access token, and refresh token) for secure communication and data sharing between systems.

Account linking enables Google Account holders to quickly, seamlessly and safely connect to your services. You may choose to implement Google Account Linking to share a user's data from your platform with Google apps and services.

The secure OAuth 2.0 protocol lets you safely link a user's Google Account with their account on your platform, thereby granting Google applications and devices access to your services.

Users can link or unlink their accounts and optionally create a new account on your platform with Google Account Linking.

Use cases

Some of the reasons to implement Google Account Linking are:

  • Share a user's data from your platform with Google apps and services.

  • Play your video and movie content using Google TV.

  • Manage and control Google Smart Home connected devices using the Google Home app and Google Assistant, "Hey Google turn on the lights".

  • Create user customized Google Assistant experiences and functionality with Conversational Actions, "Hey Google, order my usual from Starbucks".

  • Enable users to earn rewards by viewing eligible live streams on YouTube after linking their Google Account to a rewards partner account.

  • Pre-populate new accounts during sign-up with consensually shared data from a Google Account profile.

Supported features

These features are supported by Google Account Linking:

  • Quickly and easily share your data using the OAuth Linking implicit flow.

  • Provide improved security with the OAuth Linking authorization code flow.

  • Sign-in existing users or sign-up new Google verified users to your platform, obtain their consent and securely share data with Streamlined linking.

  • Reduce friction with App Flip. From a trusted Google app, one tap securely opens your verified Android or iOS app and one tap grants user consent and links accounts.

  • Improve user privacy by defining custom scopes to share only necessary data, increase user trust by clearly defining how their data is used.

  • Access to data and services hosted on your platform can be revoked by unlinking accounts. Implementing an optional token revocation endpoint lets you stay in sync with Google initiated events, while Cross-Account Protection (RISC) allows you to notify Google of any unlinking events that take place on your platform.

Account linking flows

There are 3 Google Account Linking flows all of which are OAuth based and require you to manage or control OAuth 2.0 compliant authorization and token exchange endpoints.

During the linking process, you issue access tokens to Google for individual Google Accounts after obtaining account holders consent to link their accounts and share data.

OAuth Linking ('Web OAuth')

This is the basic OAuth flow that sends users to your website for linking. The user is redirected to your website to sign in to their account. Once signed in, the user consents to sharing their data, on your service, with Google. At that point, the user's Google Account and your service, are linked.

OAuth Linking supports the authorization code and implicit OAuth flows. Your service must host an OAuth 2.0 compliant authorization endpoint for the implicit flow, and must expose both an authorization and token exchange endpoint when using the authorization code flow.

Figure 1. Account Linking on a user's phone with Web OAuth

OAuth-based App Flip Linking ('App Flip')

An OAuth flow that sends users to your app for linking.

OAuth-based App Flip Linking guides users as they move between your verified Android or iOS mobile apps and Google's platform to review the proposed data access changes and grant their consent to link their account on your platform with their Google account. To enable App Flip your service must support OAuth Linking or OAuth-based Google Sign-in Linking using the authorization code flow.

App Flip is supported for both Android and iOS.

How it works:

Google app checks if your app is installed on the user's device:

  • If the app is found, the user is ‘flipped’ to your app. Your app gathers consent from the user to link the account with Google, and then 'flips back' to the Google surface.
  • If app is not found or an error occurs during the app flip linking process, the user is redirected to Streamlined or Web OAuth flow.

Figure 2. Account Linking on a user's phone with App Flip

OAuth-based Streamlined Linking ('Streamlined')

OAuth-based Google Sign-In Streamlined linking adds Google Sign-In on top of OAuth linking, enabling users to complete linking the linking process without leaving the Google surface, thereby reducing frictions and drop-offs. OAuth-based Streamlined Linking offers the best user experience with seamless sign-in, account creation and account linking by combining Google Sign-in with OAuth linking. Your service must support OAuth 2.0 compliant authorization and token exchange endpoints. Additionally, your token exchange endpoint must support JSON Web Token (JWT) assertions and implement the check, create, and get, intents.

How it works:

Google asserts the user account and passes this information to you:

  • If an account exists for the user in your database, the user successfully links their Google account with their account on your service.
  • if no account exists for the user in your database, the user can either create a new 3P account with the asserted information Google provides : email, name, and profile picture, or choose to sign in and link with another email (this will require them to sign-in to the your service via Web OAuth).

Figure 3. Account Linking on a user's phone with Streamlined Linking

Which flow should you use?

We recommend implementing all flows to ensure users get the best linking experience. The Streamlined and App flip flows reduce linking friction as users are able to complete the linking process in very few steps. The Web OAuth linking has the lowest level of effort and is a good place to start after which you can add on the other linking flows.

Working with tokens

Google Account Linking is based upon the OAuth 2.0 industry standard.

You issue access tokens to Google for individual Google Accounts after obtaining account holders consent to link their accounts and share data.

令牌类型

OAuth 2.0 使用称为令牌的字符串在用户代理、客户端应用和 OAuth 2.0 服务器之间进行通信。

在账号关联期间,您可以使用三种类型的 OAuth 2.0 令牌:

  • 授权代码。一种短期有效的令牌,可用于交换访问令牌和刷新令牌。出于安全考虑,Google 会调用您的授权端点以获取一次性或非常短效的代码。

  • 访问令牌。授予持有者对资源的访问权限的令牌。为限制因丢失此令牌而导致的泄露风险,此令牌的有效期有限,通常会在大约一小时后过期。

  • 刷新令牌。一个长期有效的令牌,在访问令牌到期时可以交换为新的访问令牌。如果您的服务与 Google 集成,则此令牌由 Google 专门存储和使用。Google 会调用您的令牌交换端点,以便将刷新令牌换成访问令牌,后者会用于访问用户数据。

令牌处理

在使用令牌时,分片环境和客户端-服务器交换中的竞态条件可能会导致复杂的时间安排和错误处理场景。例如:

  • 您收到新的访问令牌请求,并发出新的访问令牌。同时,您会收到使用上一个未过期的访问令牌访问服务资源的请求。
  • Google 尚未收到(或从未收到)您的刷新令牌回复。与此同时,之前有效的刷新令牌会在 Google 发出的请求中使用。

由于集群中运行的异步服务、网络行为或其他原因,请求和响应可能会以任何顺序到达,也可能根本不会到达。

我们无法保证您和 Google 的令牌处理系统内部以及它们之间的共享状态是立即且完全一致的。在短时间内,多个有效、未过期的令牌可以在系统内部或不同系统之间共存。为了尽可能减少对用户的负面影响,我们建议您执行以下操作:

  • 接受未过期的访问令牌,即使已发出较新的令牌也是如此。
  • 使用刷新令牌轮替的替代方案。
  • 支持多个同时有效的访问令牌和刷新令牌。出于安全考虑,您应限制令牌数量和令牌生命周期。
维护和中断处理

在维护或意外停机期间,Google 可能无法调用您的授权或令牌交换端点来获取访问令牌和刷新令牌。

您的端点应返回 503 错误代码和空正文。在这种情况下,Google 会在有限的时间内重试失败的令牌交换请求。只要 Google 稍后能够获取刷新令牌和访问令牌,用户就不会看到失败的请求。

如果由用户发起,访问令牌请求失败会导致可见错误。如果使用隐式 OAuth 2.0 流程,用户将需要重试关联失败。

建议

您可以通过多种方法最大限度地降低维护影响。请考虑以下可选方案:

  • 维护现有服务,并将有限数量的请求路由到新更新的服务。请仅在确认预期功能后迁移所有请求。

  • 减少维护期间令牌请求的数量:

    • 将维护期限制为短于访问令牌有效期。

    • 暂时延长访问令牌生命周期:

      1. 将令牌生命周期延长到超过维护期。
      2. 等待访问令牌生命周期的两倍时间,以便用户将短时有效的令牌换成时长更长的令牌。
      3. 进入维护模式。
      4. 使用 503 错误代码和空正文响应令牌请求。
      5. 退出维护。
      6. 将令牌生命周期缩短为正常值。

Registering with Google

We'll need details of your OAuth 2.0 setup and to share credentials to enable account linking. See registration for details.