Google 助理的 Google 登入 (GSI) 提供最流暢的連結
也是開發人員最容易實作的流程。
有了 GSI,您的動作可在以下期間要求存取使用者的 Google 個人資料
對話,並在使用者同意後接收使用者名稱和電子郵件地址。
和個人資料相片你的動作就能根據這項資訊來檢查
使用者在系統中擁有 Google 帳戶。如果不是,您的動作會詢問使用者是否
他們想要根據您的 Google
個人資料內容
如果符合下列任一情況,則建議使用 GSI 做為帳戶連結解決方案:
您本身沒有驗證系統,且/或希望您的
使用者必須擁有 Google 帳戶。舉例來說,如果您的動作
我們希望所有使用者都能使用
帳戶。
Google ID 權杖:經簽署的使用者身分宣告,當中包含
使用者的基本 Google 個人資料資訊 (包括姓名、電子郵件地址和
個人資料相片) 即可。Google ID 權杖
JSON Web Token
(JWT)。
以下是已解碼的權杖範例:
{"sub":1234567890,// The unique ID of the user's Google Account"iss":"https://accounts.google.com",// The token's issuer"aud":"123-abc.apps.googleusercontent.com",// Client ID assigned to your Actions project"iat":233366400,// Unix timestamp of the token's creation time"exp":233370000,// Unix timestamp of the token's expiration time"name":"Jan Jansen","given_name":"Jan","family_name":"Jansen","email":"jan@gmail.com",// If present, the user's email address"locale":"en_US"}
帳戶登入協助程式意圖:您呼叫的輔助意圖
向 Google 助理要求帳戶連結流程如需更多資訊
請參閱「帳戶登入」。
內容字串:您加進帳戶的自訂字串
登入輔助意圖,向使用者說明該連結的原因
他們的帳戶。
運作方式
GSI 的基本流程如下:
您的動作要求使用者同意存取其 Google 個人資料。
使用者提供同意聲明後,您的動作會收到 Google ID 權杖。
包含使用者的 Google 個人資料資訊。
驗證權杖並解碼,以便讀取個人資料內容。如果您使用
Actions on Google 用戶端程式庫 for Node.js 或 Java 用戶端程式庫,
就會為您驗證符記並加以解碼
你的動作會使用這個權杖檢查使用者的 Google 個人資料
才是有效的資訊
如果有,表示使用者已使用
Google 帳戶。使用者可以繼續與
Google 助理,會將孩子的身分與他們的 Google 帳戶連結。
如果沒有的話,使用者可以使用
Google ID 權杖包含的資訊這樣一來,使用者就能
繼續透過已連結 Google 助理的帳戶繼續對話。
Google 登入流程
本節說明使用 Google 登入功能可能發生的各種流程。
流程 1:使用者資訊存在於系統中
下圖顯示使用 GSI 時發生的
使用者的資訊已存在於您的系統中:
在此情況下,您可以使用 actions.intent.SIGN_IN 輔助意圖來呼叫
您自訂的內容字串此意圖會要求使用者授予權限
存取自己的 Google 個人資料。
使用者同意後,Google 助理會傳送內含
user@gmail.com 的個人資料資訊。在本例中
包含在 user@gmail.com 的 Google ID 權杖中,與
系統因此,動作會自動連結使用者在動作中的身分
。這樣一來,您的 Webhook 就能透過
並提供相應回應
流程 2:使用者資訊不存在於您的系統中
下圖顯示使用 GSI 時發生的
使用者的資訊不存在在您的系統中:
在此情況下,Google ID 權杖所含資訊
「user@gmail.com」與系統中的帳戶不相符,因此 Google 助理
詢問使用者是否要建立新帳戶。使用者可以完成
使用語音建立帳戶,不用將帳戶轉給對方
遭到過濾的裝置。
如果使用者同意建立帳戶,您的服務就會使用
建立專屬帳戶
使用者。建立帳戶之後,使用者在動作中看見的身分
並連結至新的 Google 帳戶。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eGoogle Sign-In (GSI) offers a seamless account linking experience for Assistant users and is the easiest for developers to implement, allowing Actions to request access to a user's Google profile for name, email, and picture for account verification or creation.\u003c/p\u003e\n"],["\u003cp\u003eGSI is recommended if you lack an existing authentication system, expect all users to have Google accounts, or want to link users who have signed in using their Google accounts.\u003c/p\u003e\n"],["\u003cp\u003eUpon user consent, your Action receives a Google ID token containing user profile information, which is used to check if the user exists in your system; if so, the user is linked; if not, the user is prompted to create a new account using their Google profile.\u003c/p\u003e\n"],["\u003cp\u003eIf a user's information isn't found, they can create a new account using their Google profile, and their identity in your Action is linked to their new Google account.\u003c/p\u003e\n"]]],["Google Sign-In (GSI) allows Actions to request user's Google profile information (name, email, picture) with user consent. If the user's information exists in the system, their identity is automatically linked; otherwise, the user can create a new account using their Google profile. The Action receives a Google ID token, validates and decodes it. The user can continue using the Action after the linking of the Google account. User can be a guest if they can not be identified.\n"],null,["# Google Sign-In concept guide (Dialogflow)\n\nGoogle Sign-In (GSI) for the Assistant provides the most seamless linking\nexperience for users and is the easiest flow for developers to implement.\nWith GSI, your Action can request access to your user's Google profile during\na conversation and, if the user consents, receive the user's name, email address,\nand profile picture. Your Action can then use this information to check if the\nuser has a Google account in your system. If not, your Action asks the user if\nthey want to create a new account in your system based on their Google\nprofile information.\n| **Note:** Your user is either a) identified through voice recognition or b) configured on the device. If the user's voice is verified but not recognized, the user is considered a guest.\n\nGSI is the recommended account linking solution if any of the following applies:\n\n- You don't have an existing authentication system and/or you expect all your users to have a Google account. For example, if your Action is specifically targeting the Assistant, you can expect all your users to have Google accounts.\n- You have an existing authentication system and only want to link users who signed into your system using their Google accounts.\n\nTo verify that GSI is the right solution for you, see the\n[Choose your account linking type](/assistant/df-asdk/identity/choose-type) page.\n\nKey terms\n---------\n\nBefore you read about how GSI works, familiarize yourself with the following terms:\n\n- **Google ID token:** A signed assertion of a user's identity that contains\n a user's basic Google profile information (their name, email address, and\n profile picture). A Google ID token is a\n [JSON Web Token](https://en.wikipedia.org/wiki/JSON_Web_Token)\n (JWT).\n\n The following is an example of a decoded token:\n\n```carbon\n{\n \"sub\": 1234567890, // The unique ID of the user's Google Account\n \"iss\": \"https://accounts.google.com\", // The token's issuer\n \"aud\": \"123-abc.apps.googleusercontent.com\", // Client ID assigned to your Actions project\n \"iat\": 233366400, // Unix timestamp of the token's creation time\n \"exp\": 233370000, // Unix timestamp of the token's expiration time\n \"name\": \"Jan Jansen\",\n \"given_name\": \"Jan\",\n \"family_name\": \"Jansen\",\n \"email\": \"jan@gmail.com\", // If present, the user's email address\n \"locale\": \"en_US\"\n}\n```\n\n- **Account sign-in helper intent:** A helper intent that you call to request an account linking flow from the Assistant. For more information, see [Account Sign-in](/assistant/df-asdk/helpers#account_sign-in).\n - **Context string:** A customized string that you add to the account sign-in helper intent that tells the user why you need them to link their account.\n\nHow it works\n------------\n\nThe fundamental flow for GSI is as follows:\n\n1. Your Action asks the user for consent to access their Google profile.\n2. After the user gives consent, your Action receives a Google ID token that contains the user's Google profile information.\n3. Validate and decode the token to read the profile content. If you use the Actions on Google client library for Node.js or the Java client library, it validates and decodes the token for you.\n4. Your Action uses this token to check if the user's Google profile\n information exists in your system.\n\n 1. If it does, the user has already signed into your system with their Google account. The user can continue the conversation with the Assistant with their identity linked to their Google account.\n 2. If it doesn't, the user can create a new account in your system with\n the information contained in the Google ID token. The user can then\n continue the conversation with the Assistant with their new account linked.\n\n | **Note:** New accounts do not typically have a password set. It is recommended that you add Google Sign In to other platforms to enable users to log in via Google across the surfaces of your application. Alternatively, you can email the user a link that starts your password recovery flow to allow the user to set a password for signing in on other platforms.\n\nGoogle Sign-in flows\n--------------------\n\nThis section describes the various flows that can occur with Google Sign-in.\n| **Note:** The following flows assume the user gives consent for your Action to access their Google profile information. If a user doesn't give consent, provide them a way to continue in your Action with an alternate, limited flow. For more information, see [Best practices](/assistant/df-asdk/identity/best-practices).\n\n### Flow 1: User's information exists in your system\n\nThe following diagram shows the end-to-end flow that occurs with GSI when the\nuser's information already exists in your system:\n\n| **Note:** A line from *Webhook* to *User* represents a [simple response](/assistant/df-asdk/simple-responses) that you create and customize. Lines drawn from *Assistant* to *User* represent prompts that are owned by the Assistant and have limited options for customization (requests that require permission are always owned by the Assistant). From the user's perspective, both kinds of responses are delivered from the Assistant.\n\nIn this case, you call the `actions.intent.SIGN_IN` helper intent with a\ncontext string you customize. This intent asks the user for permission to\naccess their Google profile information.\n\nAfter the user consents, the Assistant sends a request that contains the\nprofile information for `user@gmail.com`. In this case, the information\ncontained in the Google ID token for `user@gmail.com` matches an account in\nyour system, so the user's identity in your Action is automatically linked\nto that account. Your webhook can then read the user's usual order from\na database and respond accordingly.\n\n### Flow 2: User's information does not exist in your system\n\nThe following diagram shows the end-to-end flow that occurs with GSI when\nthe user's information does not exist in your system:\n\nIn this case, the information contained in the Google ID token for\n`user@gmail.com` does not match an account in your system, so the Assistant\nasks the user if they'd like to create a new account. The user can complete\nthe account creation process with voice rather than transferring to\na screened device.\n\nWhen the user agrees to create an account, your service uses the information\nin the ID token (the user's name and email address) to create an account for\nthe user. Once the account is created, the user's identity in your Action\nis linked to their new Google account.\n\nIn this case, the user does not have a usual order because they are new to\nthe service, so your Action asks what they want to order. You\ncan also ask the user if they'd like to set their most recent order\nas their usual order."]]