تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تُدرِج ميزة "ربط التطبيقات باستخدام الوجه" المستندة إلى بروتوكول OAuth تطبيق Android في
خطوات ربط حساب Google يتطلب التدفق التقليدي لربط الحسابات
إدخال بيانات اعتماد المستخدم في المتصفِّح يؤدي استخدام ميزة "قلب التطبيقات" إلى تأجيل المستخدِم
سجّل الدخول إلى تطبيق Android، مما يتيح لك الاستفادة من
التفويضات. إذا سجَّل المستخدم الدخول إلى تطبيقك، لن يكون بحاجة إلى
إعادة إدخال بيانات الاعتماد لربط الحساب. استخدام أقل قدر ممكن من الرموز البرمجية
يجب إجراء التغييرات لتنفيذ ميزة "قلب التطبيقات" على تطبيق Android.
ستتعرّف في هذا المستند على كيفية تعديل تطبيق Android
قلب التطبيق
تجربة النموذج
نموذج التطبيق الذي يستخدم ميزة "قلب التطبيقات"
توضيح تكامل ربط الحساب المتوافق مع ميزة App Flip على Android إِنْتَ
يمكنه استخدام هذا التطبيق للتحقّق من طريقة الردّ على عملية قلب تطبيق واردة من خلال ميزة "قلب التطبيق".
تطبيقات Google للأجهزة الجوّالة.
تم ضبط نموذج التطبيق مسبقًا للدمج مع أداة اختبار قلب التطبيق).
Android،
الذي يمكنك استخدامه للتحقّق من دمج تطبيق Android مع التطبيق
يُرجى العودة قبل ضبط ربط الحساب بحساب Google. يحاكي هذا التطبيق
نية الشراء التي تظهر من خلال تطبيقات Google المتوافقة مع الأجهزة الجوّالة عند تفعيل ميزة "قلب التطبيق".
آلية العمل
يجب اتّباع الخطوات التالية لتنفيذ عملية دمج ميزة "قلب التطبيقات":
يتحقّق تطبيق Google مما إذا كان تطبيقك مثبَّتًا على الجهاز باستخدام
اسم الحزمة.
يستخدم تطبيق Google عملية فحص توقيع الحزمة للتحقّق من أنّ التطبيقات التي تم تثبيتها
هو التطبيق الصحيح.
يوفّر تطبيق Google نية بدء نشاط معيّن في تطبيقك.
يتضمّن هذا الغرض بيانات إضافية مطلوبة للربط. يتحقق أيضًا من
لمعرفة ما إذا كان تطبيقك يتوافق مع ميزة "قلب التطبيقات" من خلال حلّ هذا الغرض من خلال
إطار عمل Android.
يتحقّق تطبيقك من أنّ الطلب وارد من تطبيق Google. لإجراء ذلك،
يتحقّق تطبيقك من توقيع الحزمة ومعرِّف العميل المقدَّم.
يطلب تطبيقك رمز تفويض من خادم OAuth 2.0. في جلسة المعمل،
نهاية هذا التدفق، فإنها تعرض إما رمز تفويض أو خطأ في
تطبيق Google.
يستردّ تطبيق Google النتيجة ويواصل ربط الحساب. في حال حذف
تقديم رمز تفويض، فيتم تبادل الرمز المميّز
من خادم إلى خادم، تمامًا كما يحدث في ربط OAuth المستند إلى المتصفح
التدفق.
تعديل تطبيق Android لدعم ميزة "قلب التطبيقات"
لإتاحة ميزة "قلب التطبيقات"، عليك إجراء التغييرات التالية على الرمز البرمجي للتطبيق المتوافق مع Android:
أضِف <intent-filter> إلى ملف AndroidManifest.xml مع تنفيذ إجراء.
سلسلة تطابق القيمة التي أدخلتها في الحقل هدف قلب التطبيق
يتضمن هدف Android الذي يشغِّل تطبيقك الحقول التالية:
CLIENT_ID (String): تم تسجيل "client_id" على Google ضمن تطبيقك.
SCOPE (String[]): قائمة بالنطاقات المطلوبة
REDIRECT_URI (String): عنوان URL لإعادة التوجيه
محتوى بيانات الرد
يتم ضبط البيانات التي يتم إرجاعها إلى تطبيق Google في تطبيقك من خلال الاتصال بالرقم setResult().
وتشمل هذه البيانات ما يلي:
AUTHORIZATION_CODE (String): قيمة رمز التفويض
resultCode (int): تبلغ عن نجاح العملية أو فشلها
على إحدى القيم التالية:
Activity.RESULT_OK: يشير إلى النجاح. يتم إرجاع رمز تفويض.
Activity.RESULT_CANCELLED: إشارات إلى أنّ المستخدم ألغى
الدفع. في هذه الحالة، سيحاول تطبيق Google ربط الحساب باستخدام
عنوان URL للمصادقة.
-2: تشير إلى حدوث خطأ. أنواع مختلفة من الأخطاء
الموضحة أدناه.
ERROR_TYPE (int): نوع الخطأ، والذي يتضمّن أيًا مما يلي:
القيم التالية:
1: خطأ يمكن استرداده: سيحاول تطبيق Google ربط الحساب باستخدام
عنوان URL للمصادقة.
2: خطأ غير قابل للإصلاح: سيلغي تطبيق Google ربط الحساب.
3: معلَمات طلب غير صالحة أو مفقودة.
ERROR_CODE (int): عدد صحيح يمثّل طبيعة الخطأ للاطلاع على
معنى كل رمز خطأ، فراجع
جدول رموز الأخطاء.
ERROR_DESCRIPTION (String، اختياري): رسالة حالة يمكن لشخص عادي قراءتها
وصف الخطأ.
ويُتوقَّع ظهور قيمة للسمة AUTHORIZATION_CODE عندما
resultCode == Activity.RESULT_OK في جميع الحالات الأخرى، قيمة
يجب أن يكون الحقل "AUTHORIZATION_CODE" فارغًا. إذا كانت resultCode == -2، تكون
من المتوقّع تعبئة قيمة "ERROR_TYPE".
جدول رموز الأخطاء
يوضح الجدول أدناه رموز الأخطاء المختلفة وما إذا كان كل خطأ منها قابلاً للإصلاح أو غير قابل للإصلاح:
رمز الخطأ
المعنى
قابل للاسترداد
غير قابل للاسترداد
1
INVALID_REQUEST
✔
2
NO_INTERNET_CONNECTION
✔
3
OFFLINE_MODE_ACTIVE
✔
4
CONNECTION_TIMEOUT
✔
5
INTERNAL_ERROR
✔
6
AUTHENTICATION_SERVICE_UNAVAILABLE
✔
8
CLIENT_VERIFICATION_FAILED
✔
9
INVALID_CLIENT
✔
10
INVALID_APP_ID
✔
11
INVALID_REQUEST
✔
12
AUTHENTICATION_SERVICE_UNKNOWN_ERROR
✔
13
AUTHENTICATION_DENIED_BY_USER
✔
14
CANCELLED_BY_USER
✔
15
FAILURE_OTHER
✔
16
USER_AUTHENTICATION_FAILED
✔
بالنسبة إلى جميع رموز الأخطاء، يجب عرض نتيجة الخطأ عبر setResult إلى
لضمان ترتيب الإجراء الاحتياطي المناسب.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eOAuth-based App Flip linking streamlines account linking on Android by allowing users to sign in using existing app authorizations, eliminating the need for credential re-entry in a browser.\u003c/p\u003e\n"],["\u003cp\u003eIntegrating App Flip into your Android app involves modifying your \u003ccode\u003eAndroidManifest.xml\u003c/code\u003e, validating the calling app's signature and client ID, and handling authorization and error responses.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful authorization, your app returns an authorization code to Google; in case of errors, specific result codes and error types are returned to trigger appropriate fallback mechanisms.\u003c/p\u003e\n"],["\u003cp\u003eThe App Flip linking sample app and test tool provide resources to understand and verify your app's integration with this feature.\u003c/p\u003e\n"],["\u003cp\u003eThe launch intent from Google includes \u003ccode\u003eCLIENT_ID\u003c/code\u003e, \u003ccode\u003eSCOPE\u003c/code\u003e, and \u003ccode\u003eREDIRECT_URI\u003c/code\u003e, while the response data includes \u003ccode\u003eAUTHORIZATION_CODE\u003c/code\u003e, \u003ccode\u003eresultCode\u003c/code\u003e, and error details if applicable.\u003c/p\u003e\n"]]],[],null,["OAuth-based App Flip linking (App Flip) inserts your Android app into the\nGoogle Account Linking flow. A traditional account linking flow requires the\nuser to enter their credentials in the browser. The use of App Flip defers user\nsign-in to your Android app, which allows you to leverage existing\nauthorizations. If the user is signed in to your app, they don't need to\nre-enter their credentials to link their account. A minimal amount of code\nchanges are required to implement App Flip on your Android app.\n\nIn this document, you learn how to modify your Android app to support\nApp Flip.\n\nTry the sample\n\nThe App Flip linking [sample app](https://github.com/googlesamples/identity-appflip-android)\ndemonstrates an App Flip-compatible account linking integration on Android. You\ncan use this app to verify how to respond to an incoming App Flip intent from\nGoogle mobile apps.\n\nThe sample app is preconfigured to integrate with the [App Flip Test Tool for\nAndroid](https://github.com/googlesamples/identity-appflip-tester-android),\nwhich you can use to verify your Android app's integration with App\nFlip before you configure account linking with Google. This app simulates the\nintent triggered by Google mobile apps when App Flip is enabled.\n\nHow it works\n\nThe following steps are required to carry out an App Flip integration:\n\n1. The Google app checks if your app is installed on the device using its *package name*.\n2. The Google app uses a package signature check to validate that the installed app is the correct app.\n3. The Google app builds an intent to start a designated activity in your app. This intent includes additional data required for linking. It also checks to see if your app supports App Flip by resolving this intent through the Android framework.\n4. Your app validates that the request is coming from the Google app. To do so, your app checks the package signature and the provided client ID.\n5. Your app requests an authorization code from your OAuth 2.0 server. At the end of this flow, it returns either an authorization code or an error to the Google app.\n6. The Google app retrieves the result and continues with account linking. 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.\n\nModify your Android app to support App Flip\n\nTo support App Flip, make the following code changes to your Android app:\n\n1. Add an `\u003cintent-filter\u003e` to your `AndroidManifest.xml` file with an action\n string that matches the value you entered in the **App Flip Intent** field.\n\n \u003cactivity android:name=\"AuthActivity\"\u003e\n \u003c!-- Handle the app flip intent --\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"INTENT_ACTION_FROM_CONSOLE\"/\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\"/\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n\n2. Validate the calling app's signature.\n\n | **Note:** You need to match the package name and signature for the Google app.\n | - **Package name**: com.google.android.googlequicksearchbox\n - **Signature**: F0:FD:6C:5B:41:0F:25:CB:25:C3:B5:33:46:C8:97:2F:AE:30:F8:EE:74:11:DF:91:04:80:AD:6B:2D:60:DB:83 \n\n private fun verifyFingerprint(\n expectedPackage: String,\n expectedFingerprint: String,\n algorithm: String\n ): Boolean {\n\n callingActivity?.packageName?.let {\n if (expectedPackage == it) {\n val packageInfo =\n packageManager.getPackageInfo(it, PackageManager.GET_SIGNATURES)\n val signatures = packageInfo.signatures\n val input = ByteArrayInputStream(signatures[0].toByteArray())\n\n val certificateFactory = CertificateFactory.getInstance(\"X509\")\n val certificate =\n certificateFactory.generateCertificate(input) as X509Certificate\n val md = MessageDigest.getInstance(algorithm)\n val publicKey = md.digest(certificate.encoded)\n val fingerprint = publicKey.joinToString(\":\") { \"%02X\".format(it) }\n\n return (expectedFingerprint == fingerprint)\n }\n }\n return false\n }\n\n3. Extract the client ID from the intent parameters and verify that the client\n ID matches the expected value.\n\n private const val EXPECTED_CLIENT = \"\u003cclient-id-from-actions-console\u003e\"\n private const val EXPECTED_PACKAGE = \"\u003cgoogle-app-package-name\u003e\"\n private const val EXPECTED_FINGERPRINT = \"\u003cgoogle-app-signature\u003e\"\n private const val ALGORITHM = \"SHA-256\"\n ...\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n\n val clientId = intent.getStringExtra(\"CLIENT_ID\")\n\n if (clientId == EXPECTED_CLIENT &&\n verifyFingerprint(EXPECTED_PACKAGE, EXPECTED_FINGERPRINT, ALGORITHM)) {\n\n // ...authorize the user...\n }\n }\n\n4. Upon successful authorization, return the resulting authorization code back\n to Google.\n\n // Successful result\n val data = Intent().apply {\n putExtra(\"AUTHORIZATION_CODE\", authCode)\n }\n setResult(Activity.RESULT_OK, data)\n finish()\n\n5. If an error occurred, return an error result instead.\n\n **Note:** Do not handle the error directly within your app, instead return the error result via `setResult`. This ensures that the appropriate fallback method is trigerred if the app linking flow fails. \n\n // Error result\n val error = Intent().apply {\n putExtra(\"ERROR_TYPE\", 1)\n putExtra(\"ERROR_CODE\", 1)\n putExtra(\"ERROR_DESCRIPTION\", \"Invalid Request\")\n }\n setResult(-2, error)\n finish()\n\nContent of the launch intent\n\nThe Android intent that launches your app includes the following fields:\n\n- `CLIENT_ID` (`String`): Google `client_id` registered under your app.\n- `SCOPE` (`String[]`): A list of scopes requested.\n- `REDIRECT_URI` (`String`): The redirect URL.\n\nContent of the response data\n\nThe data returned to the Google app is set in your app by calling `setResult()`.\nThis data includes the following:\n\n- `AUTHORIZATION_CODE` (`String`): The authorization code value.\n- `resultCode` (`int`): Communicates the success or failure of the process and takes one of the following values:\n - `Activity.RESULT_OK`: Indicates success; an authorization code is returned.\n - `Activity.RESULT_CANCELLED`: Signals that the user has cancelled the process. In this case, the Google app will attempt account linking using your authorization URL.\n - `-2`: Indicates that an error has occurred. Different types of errors are described below.\n- `ERROR_TYPE` (`int`): The type of error, which takes one of the following values:\n - `1`: Recoverable error: The Google app will attempt account linking using the authorization URL.\n - `2`: Unrecoverable error: The Google app aborts account linking.\n - `3`: Invalid or missing request parameters.\n- `ERROR_CODE` (`int`): An integer representing the nature of the error. To see what each error code means, refer to the [table of error codes](#table_of_error_codes).\n- `ERROR_DESCRIPTION` (`String`, optional): Human-readable status message\n describing the error.\n\n | **Note:** See the OAuth 2.0 standard for more information on [possible errors](https://www.oauth.com/oauth2-servers/server-side-apps/possible-errors/) and the optional contents of the `error_description` field.\n\nA value for the `AUTHORIZATION_CODE` is expected when\n`resultCode == Activity.RESULT_OK`. In all other cases, the value for\n`AUTHORIZATION_CODE` needs to be empty. If `resultCode == -2`, then the\n`ERROR_TYPE` value is expected to be populated.\n\nTable of error codes\n\nThe table below shows the different error codes and whether each is a recoverable or unrecoverable error:\n\n| Error code | Meaning | Recoverable | Unrecoverable |\n|------------|----------------------------------------|-------------|---------------|\n| `1` | `INVALID_REQUEST` | ✔ | |\n| `2` | `NO_INTERNET_CONNECTION` | | ✔ |\n| `3` | `OFFLINE_MODE_ACTIVE` | ✔ | |\n| `4` | `CONNECTION_TIMEOUT` | ✔ | |\n| `5` | `INTERNAL_ERROR` | ✔ | |\n| `6` | `AUTHENTICATION_SERVICE_UNAVAILABLE` | | ✔ |\n| `8` | `CLIENT_VERIFICATION_FAILED` | ✔ | |\n| `9` | `INVALID_CLIENT` | ✔ | |\n| `10` | `INVALID_APP_ID` | ✔ | |\n| `11` | `INVALID_REQUEST` | ✔ | |\n| `12` | `AUTHENTICATION_SERVICE_UNKNOWN_ERROR` | | ✔ |\n| `13` | `AUTHENTICATION_DENIED_BY_USER` | | ✔ |\n| `14` | `CANCELLED_BY_USER` | | ✔ |\n| `15` | `FAILURE_OTHER` | | ✔ |\n| `16` | `USER_AUTHENTICATION_FAILED` | ✔ | |\n\nFor all error codes, you must return the error result via `setResult` to\nensure the appropriate fallback is trigerred."]]