統合パスを選択する
ニーズに最適な方法を選択します。
| パス | 最適な用途 | その他の情報 |
|---|---|---|
| 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 アカウントのプロフィールから同意を得て共有されたデータを使用して、新しいアカウントを事前入力します。
サポートされている機能
これらの機能は Google アカウントのリンクでサポートされています。
OAuth Linking 暗黙的フローを使用して、データをすばやく共有します。
OAuth リンクの認証コードフローでセキュリティを強化します。
既存のユーザーをログインさせるか、Google 認証済みの新規ユーザーをプラットフォームに登録させ、同意を得て、簡素化されたリンクでデータを安全に共有します。
アプリフリップで手間を軽減します。信頼できる Google アプリから、1 回タップするだけで、確認済みの Android アプリまたは iOS アプリを安全に開くことができます。また、1 回タップするだけで、ユーザーの同意を得てアカウントをリンクできます。
必要なデータのみを共有するカスタム スコープを定義することで、ユーザーのプライバシーを強化し、ユーザーデータの使用方法を明確に定義することで、ユーザーの信頼を高めます。
プラットフォームでホストされているデータやサービスへのアクセス権は、アカウントのリンクを解除することで取り消すことができます。オプションのトークン取り消しエンドポイントを実装すると、Google が開始したイベントとの同期を維持できます。また、クロス アカウント保護 (RISC)を使用すると、プラットフォームで発生したリンク解除イベントを Google に通知できます。
アカウント リンクのフロー
Google アカウントのリンクフローは 3 つあり、いずれも OAuth ベースです。OAuth 2.0 準拠の認証エンドポイントとトークン交換エンドポイントを管理または制御する必要があります。
アカウントへの関連付け中に、アカウント所有者のアカウントのリンクとデータの共有に関する同意を得た後、個々の Google アカウントに対して Google にアクセス トークンを発行します。
OAuth リンク(「ウェブ OAuth」)
これは、リンク設定のためにユーザーをウェブサイトに誘導する基本的な OAuth フローです。ユーザーは、アカウントにログインするためにウェブサイトにリダイレクトされます。ログインすると、ユーザーはサービス上のデータを Google と共有することに同意します。この時点で、ユーザーの Google アカウントとサービスがリンクされます。
OAuth Linkingは、認証コードとインプリシット OAuth フローをサポートしています。サービスは、暗黙的フロー用の OAuth 2.0 準拠の認可エンドポイントをホストする必要があります。また、認可コードフローを使用する場合は、認可エンドポイントとトークン交換エンドポイントの両方を公開する必要があります。
図 1. ユーザーのスマートフォンでのウェブ OAuth によるアカウント リンク
OAuth ベースのアプリ切り替えリンク(「アプリ切り替え」)
リンク用にユーザーをアプリに送信する OAuth フロー。
OAuth ベースのアプリ切り替えリンクでは、ユーザーが認証済みの Android または iOS モバイルアプリと Google のプラットフォームの間を移動して、提案されたデータアクセスの変更を確認し、プラットフォームのアカウントを Google アカウントにリンクすることに同意する手順が案内されます。アプリ切り替えを有効にするには、サービスが 認証コードフローを使用して OAuth リンクまたは OAuth ベースの Google でログインのリンクをサポートしている必要があります。
アプリ切り替えは、Android と iOS の両方でサポートされています。
仕組み:
Google アプリで、ご自身のアプリがユーザーのデバイスにインストールされているかどうかが確認されます。
- アプリが見つかると、ユーザーはアプリに「切り替わり」ます。アプリは、アカウントを Google にリンクするための同意をユーザーから取得し、Google サーフェスに「切り替わり」ます。
- アプリが見つからない場合や、アプリ切り替えのアカウントへの関連付けプロセス中にエラーが発生した場合は、ユーザーは Streamlined OAuth フローまたは Web OAuth フローにリダイレクトされます。
図 2. ユーザーのスマートフォンでのアプリ切り替えによるアカウント リンク
OAuth ベースの簡略化されたリンク(「簡略化された」)
OAuth ベースの Google でログインの簡素化されたリンクは、OAuth リンクの上層に Google でログインを追加します。これにより、ユーザーは Google サーフェスを離れることなくアカウントへの関連付けを完了できるため、摩擦や離脱を減らすことができます。OAuth ベースの簡素化されたリンクは、Google でログインと OAuth リンクを組み合わせることで、シームレスなログイン、アカウント作成、アカウント リンクを実現し、最高のユーザー エクスペリエンスを提供します。サービスは、OAuth 2.0 準拠の認可エンドポイントとトークン交換エンドポイントをサポートする必要があります。また、トークン交換エンドポイントは JSON ウェブトークン(JWT)アサーションをサポートし、check、create、get のインテントを実装する必要があります。
仕組み:
Google はユーザー アカウントをアサートし、この情報をデベロッパーに渡します。
- データベースにユーザーのアカウントが存在する場合、ユーザーは Google アカウントをサービスのアカウントに正常にリンクします。
- データベースにユーザーのアカウントが存在しない場合、ユーザーは Google が提供するアサーション情報(メールアドレス、名前、プロフィール写真)を使用して新しいサードパーティ アカウントを作成するか、別のメールアドレスでログインしてリンクするかを選択できます(この場合、Web 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:
- Increase token lifetime to greater than maintenance period.
- Wait twice the duration of your access token lifetime, enabling users to exchange short lived tokens for longer duration tokens.
- Enter maintenance.
- Respond to token requests with a
503error code and empty body. - Exit maintenance.
- Decrease token lifetime back to normal.
Google で登録する
アカウント リンクを有効にするには、OAuth 2.0 の設定の詳細と、認証情報の共有が必要になります。詳しくは、登録をご覧ください。