การลิงก์บัญชี Google กับการพลิกแอปตาม OAuth

OAuth-based App Flip Linking (App Flip) allows your users to quickly link their accounts in your authentication system to their Google Accounts. If your app is installed on your user's phone when they initiate the account linking process, they are seamlessly flipped to your app to obtain user authorization.

This approach provides a faster linking process since the user does not have to re-enter their username and password to authenticate; instead, App Flip leverages the credentials from the user's account on your app. Once a user has linked their Google Account with your app, they can take advantage of any integrations that you have developed.

You can set up App Flip for both iOS and Android apps.

This figure shows the steps for a user to link their Google account
            to your authentication system. The first screenshot shows how a user
            can select your app if their Google account is linked to your app.
            The second screenshot shows the confirmation for linking their
            Google account with your app. The third screenshot shows a
            successfully linked user account in the Google app.
Figure 1. Account linking on a user's phone with App Flip.

Requirements

To implement App Flip, you must fulfill the following requirements:

  • You must have an Android or iOS app.
  • You must own, manage and maintain an OAuth 2.0 server which supports the OAuth 2.0 authorization code flow.

OAuth-based App Flip Flow

The following sequence diagram details the interaction between the User, Google App, Your App, and Your Authorization Server for App Flip.

User Google App Your App Google Server Your Auth Server 1. Initiates linking 2. Deep link to Your App 3. Show Consent Screen 4. User Grants Consent 5. Get Auth Code 6. authorization_code 7. Return to Google App 8. Pass code to Google Server 9. Token Exchange (POST) 10. access_token, refresh_token 11. Store user tokens 12. Access user resources
Figure 2. The sequence of events in the App Flip flow. If an authorization code is provided, the token exchange happens server-to-server, the same way it does in the browser-based OAuth linking flow.

Roles and responsibilities

The following table defines the roles and responsibilities of the actors in the App Flip flow.

Actor / Component GAL Role Responsibilities
Google App / Server OAuth Client Initiates the linking process, triggers a deep link to your mobile app, exchanges the authorization code for tokens, and securely stores them to access your service's APIs.
Your App Authorization Agent Authenticates the user (typically using existing app credentials), obtains consent, and retrieves an authorization code from your server.
Your Authorization Server Authorization Server Validates authorization codes and refresh tokens, and issues access tokens to the Google Server.

หลักเกณฑ์การออกแบบ

ส่วนนี้อธิบายข้อกำหนดและคำแนะนำในการออกแบบหน้าจอขอความยินยอมในการลิงก์บัญชี App Flip หลังจากที่ Google เรียกใช้แอปของคุณแล้ว แอปจะแสดงหน้าจอขอความยินยอมต่อผู้ใช้

ข้อกำหนด

  1. คุณต้องแจ้งว่าระบบกำลังลิงก์บัญชีของผู้ใช้กับ Google ไม่ใช่กับผลิตภัณฑ์ Google ใดผลิตภัณฑ์หนึ่ง เช่น Google Home หรือ Google Assistant

คำแนะนำ

เราขอแนะนำให้คุณทำดังนี้

  1. แสดงนโยบายความเป็นส่วนตัวของ Google ระบุลิงก์ไปยังนโยบายความเป็นส่วนตัวของ Google ในหน้าจอขอความยินยอม

  2. ข้อมูลที่จะแชร์ ใช้ภาษาที่ชัดเจนและกระชับเพื่อบอกผู้ใช้ว่า Google ต้องการข้อมูลใดของผู้ใช้และเพราะเหตุใด

  3. คำกระตุ้นการตัดสินใจที่ชัดเจน ระบุคำกระตุ้นให้ดำเนินการที่ชัดเจนในหน้าจอความยินยอม เช่น "ยอมรับและลิงก์" เนื่องจากผู้ใช้จำเป็นต้องเข้าใจว่าต้องแชร์ข้อมูลใดกับ Google เพื่อลิงก์บัญชี

  4. ความสามารถในการปฏิเสธหรือยกเลิก จัดให้ผู้ใช้มีตัวเลือกในการย้อนกลับ ปฏิเสธ หรือยกเลิก หากเลือกที่จะไม่ลิงก์

  5. ความสามารถในการยกเลิกการลิงก์ มีกลไกให้ผู้ใช้ยกเลิกการลิงก์ เช่น URL ไปยังการตั้งค่าบัญชีในแพลตฟอร์มของคุณ หรือคุณจะใส่ลิงก์ไปยังบัญชี Google ที่ผู้ใช้ สามารถจัดการบัญชีที่ลิงก์ได้ก็ได้

  6. ความสามารถในการเปลี่ยนบัญชีผู้ใช้ แนะนำวิธีให้ผู้ใช้เปลี่ยนบัญชี ซึ่งจะเป็นประโยชน์อย่างยิ่งหากผู้ใช้มีแนวโน้มที่จะมี หลายบัญชี

    • หากผู้ใช้ต้องปิดหน้าจอขอความยินยอมเพื่อเปลี่ยนบัญชี ให้ส่งข้อผิดพลาดที่กู้คืนได้ไปยัง Google เพื่อให้ผู้ใช้ลงชื่อเข้าใช้บัญชีที่ต้องการได้ด้วยการลิงก์ OAuth และโฟลว์โดยนัย
  7. ใส่โลโก้ของคุณ แสดงโลโก้บริษัทในหน้าจอขอความยินยอม ใช้หลักเกณฑ์ด้านสไตล์เพื่อวางโลโก้ หากต้องการแสดงโลโก้ของ Google ด้วย โปรดดูโลโก้และเครื่องหมายการค้า

รูปนี้แสดงตัวอย่างหน้าจอคำยินยอมพร้อมคำอธิบายข้อกำหนดและคำแนะนำแต่ละรายการที่ควรปฏิบัติตามเมื่อออกแบบหน้าจอคำยินยอมของผู้ใช้
รูปที่ 2 หลักเกณฑ์การออกแบบหน้าจอขอความยินยอมในการลิงก์บัญชี

ใช้ App Flip ในแอป

หากต้องการใช้ App Flip คุณต้องแก้ไขรหัสการให้สิทธิ์ผู้ใช้ในแอปเพื่อยอมรับ Deep Link จาก Google

หากต้องการรองรับ App Flip ในแอป Android ให้ทำตามวิธีการในคู่มือการติดตั้งใช้งาน Android

หากต้องการรองรับ App Flip ในแอป iOS ให้ทำตามวิธีการในคู่มือการติดตั้งใช้งาน iOS

ทดสอบ App Flip

คุณอาจจำลองการพลิกแอปโดยใช้แอปตัวอย่างและแอปทดสอบก่อนที่จะมีแอปเวอร์ชันที่ใช้งานจริงที่ผ่านการยืนยันและเซิร์ฟเวอร์ OAuth 2.0 ที่ใช้งานได้

ในระหว่าง App Flip แอป Google จะเปิดแอปของคุณก่อน จากนั้นจะขอการตอบกลับรหัสการให้สิทธิ์จากเซิร์ฟเวอร์ OAuth 2.0 ของคุณ ในขั้นตอนสุดท้าย ระบบจะส่งการตอบกลับไปยังแอป Google

ข้อกำหนดเบื้องต้น

หากต้องการจำลองแอป Google และทริกเกอร์ Intent ที่เปิดแอปของคุณ ให้ดาวน์โหลดและติดตั้ง App Flip Test Tool สำหรับ Android และ iOS

ดาวน์โหลดและติดตั้ง App Flip Sample สำหรับ Android และ iOS เพื่อจำลองแอปและเลือกประเภทการตอบกลับ OAuth 2.0

ลำดับการทดสอบ

  1. เปิดเครื่องมือทดสอบการสลับแอป
  2. กด Try Flip! เพื่อเปิดแอปตัวอย่าง App Flip
  3. เลือกคำตอบจากปุ่มตัวเลือกในแอปตัวอย่าง
  4. กด Send เพื่อส่งการตอบกลับ OAuth 2.0 ที่จำลองกลับไปยังเครื่องมือทดสอบ
  5. ตรวจสอบข้อความบันทึกของเครื่องมือทดสอบเพื่อดูรายละเอียด auth_code หรือข้อผิดพลาด

การทดสอบเวอร์ชันที่ใช้งานจริง

คุณอาจทดสอบ App Flip ในเวอร์ชันที่ใช้งานจริงได้หลังจากทำการลงทะเบียนและการติดตั้งใช้งานเซิร์ฟเวอร์ OAuth 2.0 เสร็จสมบูรณ์

เราขอแนะนำให้ใช้บัญชี Google เดียวและ อีเมลเฉพาะงาน สำหรับการทดสอบอัตโนมัติ

คุณดูสถานะการลิงก์บัญชีได้โดยใช้บัญชีที่ลิงก์เมื่อลงชื่อเข้าใช้ในฐานะ ผู้ถือบัญชี Google นอกจากนี้ ระบบอาจยกเลิกการลิงก์บัญชีระหว่างการทดสอบซ้ำๆ จาก ที่นี่ด้วย

คุณอาจเลือกใช้ RISC เพื่อ ยกเลิกการลิงก์และแจ้งให้ Google ทราบถึงการเปลี่ยนแปลงโดยอัตโนมัติ