概要

統合パスを選択する

ニーズに最適な方法を選択します。

パス 最適な用途 その他の情報
Universal Commerce Protocol(UCP) 販売者と小売業者。 UCP ドキュメント
標準アカウントのリンク スマートホーム、テレビ、YouTube。 Google ドキュメント

アカウントのリンクを使用すると、Google アカウントの所有者は、サービスに迅速、シームレス、安全に接続できます。Google アカウントのリンクを実装して、プラットフォームのユーザーデータを Google のアプリやサービスと共有することもできます。

安全な OAuth 2.0 プロトコルを使用すると、ユーザーの Google アカウントとプラットフォームのアカウントを安全にリンクできるため、Google アプリやデバイスからサービスにアクセスできるようになります。

ユーザーは、アカウントをリンクしたり、リンクを解除したり、あるいは、必要に応じて Google アカウントのリンクを使って、プラットフォームで新しいアカウントを作成したりできます。

ユースケース

Google アカウントのリンクを実装する理由としては、次のようなものがあります。

  • プラットフォームのユーザーデータを Google のアプリやサービスと共有します。

  • ユニバーサル コマース プロトコル(UCP)を使用して、Google ショッピングと AI サーフェス(検索、Gemini)と統合します。

  • Google TV を使用して、動画や映画のコンテンツを再生します。

  • Google Home アプリと Google アシスタントを使用して、Google スマートホームの接続デバイスを管理、操作できます(「OK Google、照明をつけて」など)。

  • 会話型アクションを使用して、ユーザーがカスタマイズした Google アシスタントのエクスペリエンスと機能を作成します(「OK Google, スターバックスでいつもの注文をして」)。

  • ユーザーが 特典パートナー アカウントに Google アカウントをリンクした後、YouTube で対象のライブ配信を視聴して特典を獲得できるようにします。

  • 登録時に、Google アカウントのプロフィールから同意を得て共有データを使用して、新しいアカウントを事前入力します。

機能と要件

次の表に、各リンクフローのサポートと推奨事項を示します。

フローのリンク 標準の機能 UCP の機能
アプリフリップ 推奨 推奨
リンクの合理化 推奨 推奨
OAuth リンク 必須(代替) 必須(代替)
OAuth 2.1 推奨 推奨
  • 必要なデータのみを共有するカスタム スコープを定義することで、ユーザーのプライバシーを強化し、ユーザーデータの使用方法を明確に定義することで、ユーザーの信頼を高めます。

  • プラットフォームでホストされているデータやサービスへのアクセス権は、アカウントのリンクを解除することで取り消すことができます。オプションのトークン取り消しエンドポイントを実装すると、Google が開始したイベントとの同期を維持できます。また、クロス アカウント保護(RISC)を使用すると、プラットフォームで発生したリンク解除イベントを Google に通知できます。

アカウント リンクのフロー

Google アカウントのリンクフローは 3 つあり、すべて OAuth ベースです。OAuth 2.0 準拠の認可エンドポイントとトークン交換エンドポイントを管理または制御する必要があります。

アカウントへの関連付け中に、アカウント所有者のアカウントのリンクとデータの共有に関する同意を得た後、個々の Google アカウントに対して Google にアクセス トークンを発行します。

OAuth リンク

これは、ユーザーをリンク用にウェブサイトに送信する OAuth リンクフローです。ユーザーは、アカウントにログインするためにウェブサイトにリダイレクトされます。ログインすると、ユーザーはサービス上のデータを Google と共有することに同意します。この時点で、ユーザーの Google アカウントとサービスがリンクされます。

OAuth リンクは、認証コードとインプリシット OAuth フローをサポートしています。サービスは、暗黙的フロー用の OAuth 2.0 準拠の認可エンドポイントをホストする必要があります。また、認可コードフローを使用する場合は、認可エンドポイントとトークン交換エンドポイントの両方を公開する必要があります。

図 1. ユーザーのスマートフォンでの OAuth リンクによるアカウント リンク

OAuth ベースのアプリ切り替えリンク(「アプリ切り替え」)

リンク用にユーザーをアプリに送信する OAuth フロー。

OAuth ベースのアプリ切り替えリンクでは、ユーザーが認証済みの Android または iOS モバイルアプリと Google のプラットフォームの間を移動して、提案されたデータアクセスの変更を確認し、プラットフォームのアカウントを Google アカウントにリンクすることに同意する手順が案内されます。アプリ切り替えを有効にするには、サービスが認証コードフローを使用して、OAuth リンクまたは OAuth ベースの Google でログインのリンクをサポートしている必要があります。

アプリ切り替えは、AndroidiOS の両方でサポートされています。

仕組み:

Google アプリで、ご自身のアプリがユーザーのデバイスにインストールされているかどうかが確認されます。

  • アプリが見つかると、ユーザーはアプリに「切り替え」られます。アプリは、アカウントを Google にリンクするための同意をユーザーから取得し、Google サーフェスに「切り替え」て戻ります。
  • アプリが見つからない場合や、アプリ切り替えのアカウントへの関連付け処理中にエラーが発生した場合は、ユーザーは Streamlined または OAuth のリンクフローにリダイレクトされます。

図 2. ユーザーのスマートフォンでのアプリ切り替えによるアカウント リンク

OAuth ベースの簡略化されたリンク(「簡略化されたリンク」)

OAuth ベースの Google でログインの簡素化されたリンクは、OAuth リンクの上層に Google でログインを追加します。これにより、ユーザーは Google サーフェスを離れることなくアカウントへの関連付けを完了できるため、摩擦や離脱を減らすことができます。OAuth ベースの簡素化されたリンクは、Google でログインと OAuth リンクを組み合わせることで、シームレスなログイン、アカウントの作成、アカウントのリンクを実現し、最高のユーザー エクスペリエンスを提供します。サービスは、OAuth 2.0 準拠の認可エンドポイントとトークン交換エンドポイントをサポートする必要があります。また、トークン交換エンドポイントは JSON ウェブトークン(JWT)アサーションをサポートし、checkcreateget のインテントを実装する必要があります。

仕組み:

Google はユーザー アカウントをアサートし、この情報をデベロッパーに渡します。

  • データベースにユーザーのアカウントが存在する場合、ユーザーは Google アカウントをサービスのアカウントに正常にリンクします。
  • データベースにユーザーのアカウントが存在しない場合、ユーザーは Google が提供するアサーション情報(メールアドレス、名前、プロフィール写真)を使用して新しいサードパーティ アカウントを作成するか、別のメールアドレスでログインしてリンクするかを選択できます(この場合、OAuth リンクを使用してサービスにログインする必要があります)。

図 3. ユーザーのスマートフォンでの簡素化されたリンクによるアカウント リンク

どのフローを使用すればよいですか?

ユーザーに最適なリンク エクスペリエンスを提供するため、すべてのフローを実装することをおすすめします。簡素化されたフローとアプリ切り替えフローでは、ユーザーが少ない手順でアカウントへの関連付けプロセスを完了できるため、リンクの摩擦が軽減されます。OAuth リンクフローは最も手間がかからず、最初に始めるのに適しています。その後、他のリンクフローを追加できます。

トークンを操作する

Google アカウントのリンクは、OAuth 2.0 業界標準に基づいています。

アカウント所有者の同意を得てアカウントをリンクし、データを共有した後、個々の Google アカウントに対して Google にアクセス トークンを発行します。

Token types

OAuth 2.0 uses strings called tokens to communicate between the user agent, the client application, and the OAuth 2.0 server.

Three types of OAuth 2.0 tokens can be used during account linking:

  • Authorization code. A short-lived token that can be exchanged for an access and a refresh token. For security purposes, Google calls your authorization endpoint to obtain a single use or very short-lived code.

  • Access token. A token that grants the bearer access to a resource. To limit exposure that could result from the loss of this token, it has a limited lifetime, usually expiring after an hour or so.

  • Refresh token. A long-lived token that can be exchanged for a new access token when an access token expires. When your service integrates with Google, this token is exclusively stored and used by Google. Google calls your token exchange endpoint to exchange refresh tokens for access tokens, which are in turn used to access user data.

Token handling

Race conditions in clustered environments and client-server exchanges can result in complex timing and error handling scenarios when working with tokens. For example:

  • You receive a request for a new access token, and you issue a new access token. Concurrently, you receive a request for access to your service's resource using the previous, unexpired access token.
  • Your refresh token reply is yet to be received (or is never received) by Google. Meanwhile, the previously valid refresh token is used in a request from Google.

Requests and replies can arrive in any order, or not at all due to asynchronous services running in a cluster, network behavior, or other means.

Immediate and fully consistent shared state both within, and between, your and Google's token handling systems cannot be guaranteed. Multiple valid, unexpired tokens can coexist within or across systems short period of time. To minimize negative user impact we recommend you do the following:

  • Accept unexpired access tokens, even after a newer token is issued.
  • Use alternatives to Refresh Token Rotation.
  • Support multiple, concurrently valid access and refresh tokens. For security, you should limit the number of tokens and token lifetime.
Maintenance and outage handling

During maintenance or unplanned outages Google might be unable to call your authorization or token exchange endpoints to obtain access and refresh tokens.

Your endpoints should respond with a 503 error code and empty body. In this case, Google retries failed token exchange requests for a limited time. Provided that Google is later able to obtain refresh and access tokens, failed requests are not visible to users.

Failing requests for an access token result in a visible error, if initiated by a user. Users will be required to retry linking failures if the implicit OAuth 2.0 flow is used.

Recommendations

There are many solutions to minimize maintenance impact. Some options to consider:

  • Maintain your existing service and route a limited number of requests to your newly updated service. Migrate all requests only after confirming expected functionality.

  • Reduce the number of token requests during the maintenance period:

    • Limit maintenance periods to less than the access token lifetime.

    • Temporarily increase the access token lifetime:

      1. Increase token lifetime to greater than maintenance period.
      2. Wait twice the duration of your access token lifetime, enabling users to exchange short lived tokens for longer duration tokens.
      3. Enter maintenance.
      4. Respond to token requests with a 503 error code and empty body.
      5. Exit maintenance.
      6. Decrease token lifetime back to normal.

永続的なリンク

永続的なリンクは、安定した統合のコア要件です。これにより、ネットワークの一時的な障害や定期的な認証情報の更新が発生した場合でも、ユーザー アカウントのリンクが維持されます。

永続的なリンクを実装するには、「スライディング ウィンドウ」アプローチを使用します。つまり、更新トークンをローテーションするのではなく、既存の更新トークンの有効期限を延長します(RFC 6749 セクション 6 を参照)。これにより、新しい更新トークンが発行されたものの、Google が正常に受信または保存できなかった場合に発生する可能性のある競合状態や意図しないリンク解除を防ぐことができます。

Google で登録する

アカウント リンクを有効にするには、OAuth 2.0 の設定の詳細と、認証情報の共有が必要です。詳しくは、登録をご覧ください。