تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إذا سبق لك دمج واجهة برمجة التطبيقات لتسجيل الدخول باستخدام حساب Google باستخدام GoogleAuthUtil.getToken أو Plus.API، عليك الانتقال إلى أحدث واجهة برمجة تطبيقات لتسجيل الدخول لزيادة الأمان وتحسين تجربة المستخدم.
نقل البيانات من رمز الدخول غير المتوافق
يجب عدم إرسال رموز الوصول التي تم الحصول عليها باستخدام GoogleAuthUtil.getToken إلى
خادم الخلفية كبيان هوية، لأنّه لا يمكنك التحقّق بسهولة
من أنّ الرمز مُصدَر لخادم الخلفية، ما يجعلك عرضة لإدراج
رمز وصول من مهاجم.
على سبيل المثال، إذا كان رمز Android يبدو مثل المثال أدناه، عليك
نقل تطبيقك إلى أفضل الممارسات الحالية.
في المثال، تستخدم طلبات رمز الدخول oauth2: بالإضافة إلى سلسلة نطاق كمعلمة scope لطلب GoogleAuthUtil.getToken (oauth2:https://www.googleapis.com/auth/plus.login).
بدلاً من المصادقة باستخدام رمز مميّز للوصول تم الحصول عليه باستخدام
GoogleAuthUtil.getToken، استخدِم إما عملية الحصول على رمز تعريف أو عملية الحصول على رمز التفويض.
نقل البيانات إلى مسار الرمز المميّز للهوية
إذا كنت بحاجة فقط إلى رقم تعريف المستخدم أو عنوان بريده الإلكتروني أو اسمه أو عنوان URL لصورة ملفه الشخصي،
استخدِم مسار رمز تعريف.
لنقل البيانات إلى مسار رمز التعريف، عليك إجراء التغييرات التالية:
الجانب العميل من Android
إزالة إذن GET_ACCOUNTS (جهات الاتصال) إذا طلبت ذلك
يمكنك تبديل أي رمز باستخدام GoogleAuthUtil أو Plus.API أو
AccountPicker.newChooseAccountIntent() أو
AccountManager.newChooseAccountIntent() إلى Auth.GOOGLE_SIGN_IN_API من خلال
الضبط GoogleSignInOptions.Builder.requestIdToken(...).
إيقاف نقطة النهاية القديمة بعد نقل بيانات تطبيقات العملاء
الانتقال إلى مسار رمز مصادقة الخادم
إذا كان خادمك بحاجة إلى الوصول إلى واجهات برمجة تطبيقات Google الأخرى، مثل Google Drive أو YouTube
أو "جهات الاتصال"، استخدِم مسار رمز مصادقة الخادم.
لنقل البيانات إلى مسار رمز مصادقة الخادم، عليك إجراء التغييرات التالية:
الجانب العميل من Android
إزالة إذن "GET_ACCOUNTS" (جهات الاتصال) إذا طلبته
بدِّل أي رمز يستخدم GoogleAuthUtil أو Plus.API أو
AccountPicker.newChooseAccountIntent() أو
AccountManager.newChooseAccountIntent() إلى Auth.GOOGLE_SIGN_IN_API باستخدام الإعداد
GoogleSignInOptions.Builder.requestServerAuthCode(...).
إيقاف نقطة النهاية القديمة بعد نقل بيانات تطبيقات العملاء
وسيظل بإمكانك مشاركة منطق الوصول إلى واجهة برمجة التطبيقات بين نقطتَي النهاية القديمة والجديدة. على سبيل المثال:
GoogleTokenResponsetokenResponse=newGoogleAuthorizationCodeTokenRequest(...);StringaccessToken=tokenResponse.getAccessToken();StringrefreshToken=tokenResponse.getRefreshToken();LongexpiresInSeconds=tokenResponse.getExpiresInSeconds();// Shared by your old and new implementation, old endpoint can pass null for refreshTokenprivatevoiddriveAccess(StringrefreshToken,StringaccessToken,LongexpiresInSeconds){GoogleCredentialcredential=newGoogleCredential.Builder().setTransPort(...)....build();credential.setAccessToken(accessToken);credential.setExpiresInSeconds(expiresInSeconds);credential.setRefreshToken(refreshToken);}
نقل البيانات من مسار رمز تعريف GoogleAuthUtil
إذا كنت تستخدم GoogleAuthUtil للحصول على الرموز المميّزة للتعريف، عليك نقل البيانات إلى مسار الرمز المميّز الجديد لواجهة برمجة التطبيقات لتسجيل الدخول.
على سبيل المثال، إذا كان رمز Android يبدو مثل المثال التالي، عليك
نقل البيانات:
في المثال، تستخدم طلبات الرموز المميّزة للمعرّف audience:server:client_id بالإضافة إلى
معرّف العميل لخادم الويب كمعلمة "النطاق" لاستدعاء
GoogleAuthUtil.getToken
(audience:server:client_id:9414861317621.apps.googleusercontent.com).
توفّر عملية الحصول على الرمز المميّز لتعريف المستخدم في واجهة برمجة التطبيقات Sign-In API الجديدة المزايا التالية:
تجربة تسجيل الدخول بنقرة واحدة بطريقة مبسّطة
يمكن لخادمك الحصول على معلومات الملف الشخصي للمستخدم بدون طلب إضافي من الشبكة.
لنقل البيانات إلى مسار رمز التعريف، عليك إجراء التغييرات التالية:
الجانب العميل من Android
إزالة إذن GET_ACCOUNTS (جهات الاتصال) إذا طلبت ذلك
يمكنك تبديل أي رمز باستخدام GoogleAuthUtil أو Plus.API أو
AccountPicker.newChooseAccountIntent() أو
AccountManager.newChooseAccountIntent() إلى Auth.GOOGLE_SIGN_IN_API من خلال
الضبط GoogleSignInOptions.Builder.requestIdToken(...).
من جهة الخادم
تُصدر واجهة برمجة التطبيقات الجديدة Sign-In API رموزًا مميّزة لتعريف المستخدمين تتوافق مع مواصفات OpenID Connect
، على عكس GoogleAuthUtil.getToken التي تستخدم تنسيقًا تم إيقافه نهائيًا.
على وجه التحديد، جهة الإصدار الآن هي https://accounts.google.com، باستخدام مخطّط https.
أثناء عملية نقل البيانات، يجب أن يُثبت خادمك صحة رمز التعريف من كل من
عملاء Android القديم والجديد. للتحقّق من صحة تنسيقَي الرمز المميّز، عليك إجراء
التغيير المناسب لمكتبة العميل التي تستخدمها (إذا كنت تستخدم مكتبة):
Java (مكتبات برامج Google APIs): الترقية إلى الإصدار 1.21.0 أو إصدار أحدث
PHP (مكتبات عملاء واجهات برمجة تطبيقات Google): إذا كنت تستخدم الإصدار 1، عليك الترقية إلى الإصدار 1.1.6 أو إصدار أحدث،
وإذا كنت تستخدم الإصدار 2، عليك الترقية إلى الإصدار 2.0.0-RC1 أو إصدار أحدث.
Node.js: الترقية إلى الإصدار 0.9.7 أو إصدار أحدث
Python أو عمليات التنفيذ الخاصة بك: قبول كل من هذين الناشرَين:
https://accounts.google.com وaccounts.google.com
نقل البيانات من مسار رمز مصادقة الخادم GoogleAuthUtil
إذا كنت تستخدم GoogleAuthUtil للحصول على رمز مصادقة الخادم، عليك نقل البيانات إلى مسار رمز المصادقة الجديد في واجهة برمجة التطبيقات Sign-In API.
على سبيل المثال، إذا كان رمز Android يبدو مثل المثال التالي، عليك
نقل البيانات:
في المثال، تستخدِم طلبات الحصول على رمز مصادقة الخادم oauth2:server:client_id +
معرّف العميل لخادم الويب كمَعلمة scope لإجراء طلب GoogleAuthUtil.getToken (oauth2:server:client_id:9414861317621.apps.googleusercontent.com).
توفّر مسار رمز المصادقة الجديد لواجهة برمجة التطبيقات Sign-In API المزايا التالية:
تجربة تسجيل الدخول بنقرة واحدة بطريقة مبسّطة
في حال اتّباع دليل نقل البيانات أدناه، يمكن لخادمك الحصول على رمز تعريف
يحتوي على معلومات الملف الشخصي للمستخدم عند إجراء عملية تبادل رمز المصادقة.
لنقل البيانات إلى مسار المصادقة الجديد، عليك إجراء التغييرات التالية:
الجانب العميل من Android
إزالة إذن "GET_ACCOUNTS" (جهات الاتصال) إذا طلبته
بدِّل أي رمز يستخدم GoogleAuthUtil أو Plus.API أو
AccountPicker.newChooseAccountIntent() أو
AccountManager.newChooseAccountIntent() إلى Auth.GOOGLE_SIGN_IN_API باستخدام الإعداد
GoogleSignInOptions.Builder.requestServerAuthCode(...).
من جهة الخادم
احتفظ برمزك الحالي، ولكن حدِّد https://oauth2.googleapis.com/token
كنقطة نهاية خادم الرموز المميّزة عند إنشاء GoogleAuthorizationCodeTokenRequest، حتى تتمكّن من الحصول على رمز تعريف
يحتوي على عنوان البريد الإلكتروني للمستخدم ومعرّفه ومعلومات ملفه الشخصي بدون الحاجة إلى إجراء https://oauth2.googleapis.com/tokenطلب آخر على الشبكة. هذه النهاية متوافقة تمامًا مع الإصدارات القديمة، وسيعمل الرمز التالي
مع رموز مصادقة الخادم التي يتم استرجاعها من عمليات تنفيذ العميل
القديم والجديد لنظام التشغيل Android.
تاريخ التعديل الأخير: 2024-11-09 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2024-11-09 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eGoogle Sign-In for Android is outdated and developers should migrate to Credential Manager for enhanced security and user experience.\u003c/p\u003e\n"],["\u003cp\u003eAvoid sending access tokens directly to backend servers for authentication; instead, utilize the ID token or server auth code flow.\u003c/p\u003e\n"],["\u003cp\u003eMigrating to the ID token flow is recommended for retrieving basic user information like ID, email, and profile details.\u003c/p\u003e\n"],["\u003cp\u003eThe server auth code flow is suitable for accessing Google APIs beyond user profile data, such as Google Drive or YouTube.\u003c/p\u003e\n"],["\u003cp\u003eWhen migrating from GoogleAuthUtil, ensure your server can verify ID tokens from both old and new clients by updating client libraries or accepting both issuer formats.\u003c/p\u003e\n"]]],[],null,["# Migrate from GoogleAuthUtil and Plus.API\n\n| **Warning:** Google Sign-In for Android is outdated and no longer supported. To ensure the continued security and usability of your app, [migrate\n| to Credential Manager](https://developer.android.com/training/sign-in/credential-manager/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience. For Wear developers: Credential Manager will be supported in Wear OS 5.1 and later on selected watches. Developers actively supporting Wear OS 3, 4 and 5.0 devices with Sign in with Google should continue using Google Sign-in for Android for your Wear applications. Sign in with Google support will be available on Credential Manager APIs for these versions of WearOS at a later date.\n\nIf you integrated with Google Sign-In in the past using\n`GoogleAuthUtil.getToken` or `Plus.API`, you should migrate to the newest\nSign-In API for greater security and a better user experience.\n\nMigrate from access token anti-pattern\n--------------------------------------\n\nYou should not send access tokens obtained with `GoogleAuthUtil.getToken` to\nyour backend server as an identity assertion, since you cannot easily verify\nthat the token was issued to your backend, leaving you vulnerable to insertion\nof an access token from an attacker.\n\nFor example, if your Android code looks like the example below, you should\nmigrate your app to the current best practices.\n\nIn the example, access token requests use `oauth2:` plus a scope string as the\n`scope` parameter for the `GoogleAuthUtil.getToken` call\n(`oauth2:https://www.googleapis.com/auth/plus.login`).\n\nInstead of authenticating with an access token acquired with\n`GoogleAuthUtil.getToken`, use either the ID token flow or the auth code flow.\n\n### Migrate to the ID token flow\n\nIf all you need is the user's ID, email address, name, or profile picture URL,\nuse the [ID token flow](/identity/sign-in/android/backend-auth).\n\nTo migrate to the ID token flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestIdToken(...)` configuration.\n\n#### Server side\n\n- Create a new endpoint for [ID token auth](/identity/sign-in/android/backend-auth)\n- Turn off the old endpoint after your client apps are migrated\n\n### Migrate to the server auth code flow\n\nIf your server needs to access other Google APIs, such as Google Drive, Youtube,\nor Contacts, use the [server auth code flow](/identity/sign-in/android/offline-access).\n\nTo migrate to the server auth code flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestServerAuthCode(...)` configuration.\n\n#### Server side\n\n- Create a new endpoint for the [server auth code flow](/identity/sign-in/android/offline-access)\n- Turn off the old endpoint after your client apps are migrated\n\nYou can still share API access logic between your old and new endpoints. For\nexample: \n\n```carbon\nGoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(...);\nString accessToken = tokenResponse.getAccessToken();\nString refreshToken = tokenResponse.getRefreshToken();\nLong expiresInSeconds = tokenResponse.getExpiresInSeconds();\n\n// Shared by your old and new implementation, old endpoint can pass null for refreshToken\nprivate void driveAccess(String refreshToken, String accessToken, Long expiresInSeconds) {\n GoogleCredential credential = new GoogleCredential.Builder()\n .setTransPort(...)\n ...\n .build();\n credential.setAccessToken(accessToken);\n credential.setExpiresInSeconds(expiresInSeconds);\n credential.setRefreshToken(refreshToken);\n}\n```\n\nMigrate from the GoogleAuthUtil ID token flow\n---------------------------------------------\n\nIf you use `GoogleAuthUtil` to get ID tokens, you should migrate to the new\nSign-In API [ID token flow](/identity/sign-in/android/backend-auth).\n\nFor example, if your Android code looks like the following example, you should\nmigrate:\n\nIn the example, ID token requests use `audience:server:client_id` plus the\nclient ID for your web server as the 'scope' parameter for the\n`GoogleAuthUtil.getToken` call\n(`audience:server:client_id:9414861317621.apps.googleusercontent.com`).\n\nThe new Sign-In API ID token flow has the following benefits:\n\n- Streamlined one-tap sign-in experience\n- Your server can get user profile information without an extra network call\n\nTo migrate to the ID token flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestIdToken(...)` configuration.\n\n#### Server side\n\nThe new Sign-In API issues ID tokens that comply with the OpenID Connect\nspecification, unlike `GoogleAuthUtil.getToken`, which uses a deprecated format.\nIn particular, the issuer is now `https://accounts.google.com`, with a `https`\nschema.\n\nDuring your migration process, your server needs to verify ID token from both\nyour old and new Android clients. To verify both formats of the token, make the\nchange that corresponds to the client library you use (if you use one):\n\n- Java (Google APIs Client Libraries): upgrade to 1.21.0 or newer\n- PHP (Google APIs Client Libraries): if you use v1, upgrade to 1.1.6 or newer; if you use v2, upgrade to 2.0.0-RC1 or newer\n- Node.js: upgrade to 0.9.7 or newer\n- Python or your own implementations: accept both of these issuers: `https://accounts.google.com` and `accounts.google.com`\n\nMigrate from the GoogleAuthUtil server auth code flow\n-----------------------------------------------------\n\nIf you use `GoogleAuthUtil` to get a server auth code, you should migrate to the\nnew Sign-In API [auth code flow](/identity/sign-in/android/offline-access).\n\nFor example, if your Android code looks like the following example, you should\nmigrate:\n\nIn the example, server auth code requests use `oauth2:server:client_id` + the\nclient ID for your web server as the `scope` parameter for the\n`GoogleAuthUtil.getToken` call (`oauth2:server:client_id:9414861317621.apps.googleusercontent.com`).\n\nThe new Sign-In API auth code flow has the following benefits:\n\n- Streamlined one-tap sign-in experience\n- If you follow the migration guide below, your server can get an ID token containing the user's profile information when you do the auth code exchange\n\nTo migrate to the new auth code flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestServerAuthCode(...)` configuration.\n\n#### Server side\n\nKeep your current code, but specify `https://oauth2.googleapis.com/token`\nas the token server endpoint when constructing the\n`GoogleAuthorizationCodeTokenRequest` object, so that you can get an ID token\nwith the user's email, user ID, and profile info without the need for another\nnetwork call. This endpoint is fully backward compatible, and the below code\nwill work for server auth codes retrieved from both your old and new Android\nclient implementations. \n\n```css+lasso\nGoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(\n transport,\n jsonFactory,\n // Use below for tokenServerEncodedUrl parameter\n \"https://oauth2.googleapis.com/token\",\n clientSecrets.getDetails().getClientId(),\n clientSecrets.getDetails().getClientSecret(),\n authCode,\n REDIRECT_URI)\n .execute();\n\n...\n\n// You can also get an ID token from auth code exchange.\nGoogleIdToken googleIdToken = tokenResponse.parseIdToken();\nGoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)\n .setAudience(Arrays.asList(SERVER_CLIENT_ID))\n .setIssuer(\"https://accounts.google.com\")\n .build();\n// Refer to ID token documentation to see how to get data from idToken object.\nGoogleIdToken idToken = verifier.verify(idTokenString);\n...\n```\n| **Note:** If you use the server auth code flow, but only need to access the user's profile information on your server, consider switching to the recommended [ID token flow](/identity/sign-in/android/backend-auth)."]]