پیوند دادن حساب Google با App Flip مبتنی بر OAuth، پیوند حساب Google با App Flip مبتنی بر 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.

设计准则

本部分介绍了应用翻转账号关联同意屏幕的设计要求和建议。在 Google 调用您的应用后,您的应用会向用户显示同意屏幕。

要求

  1. 您必须告知用户,其账号将与 Google 关联,而非与 Google Home 或 Google 助理等特定 Google 产品关联。

建议

建议您执行以下操作:

  1. 显示 Google 的隐私权政策。在意见征求屏幕上添加指向 Google 隐私权政策的链接。

  2. 要分享的数据。使用简洁明了的语言告知用户 Google 需要哪些用户数据以及原因。

  3. 明确的号召性用语。在同意屏幕上提供清晰的号召性用语,例如“同意并关联”。这是因为用户需要了解他们必须与 Google 分享哪些数据才能关联其账号。

  4. 能够拒绝或取消。如果用户选择不关联,请提供一种供用户返回、拒绝或取消的方式。

  5. 能够解除关联。提供一种可供用户取消关联的机制,例如指向您平台上的账号设置的网址。或者,您也可以添加指向 Google 账号的链接,以便用户管理其关联的账号。

  6. 能够更改用户账号。建议用户切换账号的方法。如果用户倾向于使用多个账号,此功能尤其有用。

    • 如果用户必须关闭同意屏幕才能切换账号,请向 Google 发送可恢复的错误,以便用户可以通过 OAuth 关联隐式流程登录所需账号。
  7. 添加您的徽标。在权限请求页面上显示公司徽标。 根据样式指南放置徽标。如果您还想显示 Google 的徽标,请参阅徽标和商标

此图显示了一个同意屏幕示例,其中包含在设计用户同意屏幕时应遵循的各项要求和建议。
图 2. 账号关联意见征求界面设计指南。

پیاده‌سازی App Flip در برنامه‌هایتان

برای پیاده‌سازی App Flip، باید کد مجوز کاربر را در برنامه خود تغییر دهید تا یک لینک عمیق از گوگل را بپذیرد.

برای پشتیبانی از App Flip در برنامه اندروید خود، دستورالعمل‌های موجود در راهنمای پیاده‌سازی اندروید را دنبال کنید.

برای پشتیبانی از App Flip در برنامه iOS خود، دستورالعمل‌های موجود در راهنمای پیاده‌سازی iOS را دنبال کنید.

تست برنامه تلنگر

قبل از اینکه برنامه‌های کاربردی تأیید شده و یک سرور OAuth 2.0 کارآمد در دسترس قرار گیرند، می‌توان App Flip را با استفاده از برنامه‌های نمونه و آزمایشی شبیه‌سازی کرد.

در طول App Flip، برنامه گوگل ابتدا برنامه شما را باز می‌کند و سپس از سرور OAuth 2.0 شما درخواست کد مجوز می‌کند و در مرحله آخر پاسخ به برنامه گوگل بازگردانده می‌شود.

پیش‌نیازها

برای شبیه‌سازی یک برنامه گوگل و فعال کردن intent که برنامه شما را اجرا می‌کند، ابزار App Flip Test را برای اندروید و iOS دانلود و نصب کنید.

برای شبیه‌سازی برنامه خود و انتخاب نوع پاسخ OAuth 2.0، App Flip Sample را برای اندروید و iOS دانلود و نصب کنید.

توالی آزمایش

  1. ابزار تست چرخش برنامه را باز کنید.
  2. برای اجرای برنامه نمونه App Flip خود، دکمه Try Flip! را فشار دهید.
  3. یک پاسخ را از دکمه‌های رادیویی در برنامه Sample انتخاب کنید.
  4. برای ارسال پاسخ شبیه‌سازی‌شده‌ی OAuth 2.0 به ابزار تست، Send فشار دهید.
  5. پیام‌های لاگ ابزار تست را برای کد تایید یا جزئیات خطا بررسی کنید.

آزمایش تولید

App Flip می‌تواند پس از تکمیل ثبت‌نام و پیاده‌سازی سرور OAuth 2.0 شما، در محیط عملیاتی آزمایش شود.

برای تست خودکار، یک حساب گوگل و یک آدرس ایمیل مخصوص کار توصیه می‌شود.

وضعیت اتصال حساب‌ها را می‌توان با استفاده از حساب‌های پیوند شده، هنگام ورود به سیستم به عنوان دارنده حساب گوگل، مشاهده کرد. همچنین ممکن است اتصال حساب‌ها بین آزمایش‌های مکرر از اینجا قطع شود.

به صورت اختیاری، می‌توانید RISC را پیاده‌سازی کنید تا به صورت برنامه‌نویسی شده، اتصال را قطع کرده و گوگل را از این تغییر مطلع کنید.