تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
بعد استرداد بيانات اعتماد المستخدم أو استرداد تلميحات تسجيل الدخول بنجاح، يمكنك التحقّق مما إذا كان رمز التعريف متاحًا لبيانات الاعتماد. رمز التعريف هو تأكيد موقّع لهوية المستخدم ويتضمّن أيضًا معلومات الملف الشخصي الأساسية للمستخدم، وقد يتضمّن عنوان بريد إلكتروني تم إثبات ملكيته من خلال Google. عند توفّر رموز التعريف، يمكنك استخدامها للمصادقة بشكل آمن مع الخلفية البرمجية لتطبيقك، أو لتخطّي خطوة تأكيد عنوان البريد الإلكتروني عند إنشاء حساب جديد.
يتوفّر رمز مميّز للمعرّف عندما يتطابق معرّف المستخدم الخاص بكائن Credential مع معرّف المستخدم الخاص بحساب Google الذي تم تسجيل الدخول إليه على الجهاز.
لتسجيل الدخول باستخدام رمز مميّز للمعرّف، عليك أولاً استرداد الرمز المميز للمعرّف باستخدام طريقة getIdTokens. بعد ذلك، أرسِل الرمز المميّز لتعريف الهوية إلى الخلفية في تطبيقك. في الخلفية، تحقَّق من صحة الرمز المميّز باستخدام إحدى مكتبات برامج Google API أو إحدى مكتبات JWT للأغراض العامة.
يجب استدعاء setAccountTypes(IdentityProviders.GOOGLE) عند إنشاء العنصرَين CredentialRequest وHintRequest.
الحصول على رمز مميّز للمعرّف من عنصر بيانات الاعتماد
بعد استرداد بيانات اعتماد المستخدم، تحقَّق مما إذا كان العنصر Credentials يتضمّن رمز تعريف. إذا كان الأمر كذلك، اتّصِل بالرقم getIdTokens لاسترداده، وأرسِله إلى الخلفية باستخدام HTTPS POST.
if(!credential.getIdTokens().isEmpty()){StringidToken=credential.getIdTokens().get(0).getIdToken();HttpClienthttpClient=newDefaultHttpClient();HttpPosthttpPost=newHttpPost("https://yourbackend.example.com/tokensignin"); try { List nameValuePairs = new ArrayList(1); nameValuePairs.add(new BasicNameValuePair("idToken", idToken)); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpClient.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); final String responseBody = EntityUtils.toString(response.getEntity()); Log.i(TAG, "Signedinas:"+responseBody);}}
التحقّق من رمز التعريف على الخلفية
بعد تلقّي رمز التعريف من خلال HTTPS POST، عليك التحقّق من توقيع الرمز والتحقّق من مطالبات aud وiss وexp الخاصة بالرمز.
تتضمّن مطالبة aud برمز تعريف من خدمة "Smart Lock لكلمات المرور" التنسيق التالي:
android://SHA512_HASH@ANDROID_PACKAGE_NAME
القيمة SHA512HASH هي تجزئة SHA-512 لشهادة التوقيع. يمكنك الحصول على هذه القيمة باستخدام الأداتَين المساعدتَين keytool وopenssl:
أو يمكنك الحصول على قيمة التجزئة SHA-512 من خلال فحص رمز مميّز صالح تعرفه.
يمكن لمكتبات JWT معالجة بعض مهام التحقّق هذه نيابةً عنك. على سبيل المثال،
باستخدام مكتبة Google Auth للغة Java:
importcom.google.api.client.googleapis.auth.oauth2.GoogleIdToken;importcom.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;importcom.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;...//Verifierthatchecksthatthetokenhastheproperissuerandaudience,//andhasn't expiredprivatestaticGoogleIdTokenVerifierverifier=newGoogleIdTokenVerifier.Builder(transport,jsonFactory).setAudience(Arrays.asList(String.format("android://%s@%s",SHA512_HASH,PACKAGE_NAME))).build();//(ReceiveidTokenStringbyHTTPSPOST)GoogleIdTokenidToken=verifier.verify(idTokenString);if(idToken!=null){Payloadpayload=idToken.getPayload();System.out.println("User email: "+payload.getEmail());if(payload.getEmailVerified()){System.out.println("Email verified by Google.");}}else{System.out.println("Invalid ID token.");}
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eSmart Lock for Passwords is deprecated; migrate to Credential Manager for enhanced security and user experience using passkeys, passwords, and federated identities.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve ID tokens from retrieved credentials or sign-in hints to authenticate with your backend or streamline account creation.\u003c/p\u003e\n"],["\u003cp\u003eTo use ID tokens, ensure your app can retrieve credentials or hints, and specify \u003ccode\u003eIdentityProviders.GOOGLE\u003c/code\u003e when requesting credentials.\u003c/p\u003e\n"],["\u003cp\u003eAfter retrieving a credential, get the ID token using \u003ccode\u003egetIdTokens\u003c/code\u003e and send it to your backend for verification using a JWT library or a Google API client.\u003c/p\u003e\n"],["\u003cp\u003eOn the backend, verify the ID token's signature and claims (\u003ccode\u003eaud\u003c/code\u003e, \u003ccode\u003eiss\u003c/code\u003e, \u003ccode\u003eexp\u003c/code\u003e), with the \u003ccode\u003eaud\u003c/code\u003e claim containing your app's package name and signing certificate hash.\u003c/p\u003e\n"]]],[],null,["| **Deprecated:** Smart Lock for Passwords is deprecated. To ensure the continued security and usability of your app, [migrate to\n| Credential Manager](https://developer.android.com/training/sign-in/passkeys/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience.\n\nAfter you have successfully [retrieved a user's credentials](/identity/smartlock-passwords/android/retrieve-credentials#handle_successful_credential_requests)\nor [retrieved sign-in hints](/identity/smartlock-passwords/android/retrieve-hints),\nyou can check if an ID token is available for the credential. An ID token is a\nsigned assertion of a user's identity that also contains a user's basic profile\ninformation, possibly including an email address that has been verified by\nGoogle. When ID tokens are available, you can use them to securely\nauthenticate with your app's backend, or to skip the email verification step\nwhen creating a new account.\n\nAn ID token is available when a `Credential` object's user ID matches the user\nID of a Google account that is signed in on the device.\n\nTo sign in with an ID token, first retrieve the ID token with the [`getIdTokens`](/android/reference/com/google/android/gms/auth/api/credentials/Credential#getIdTokens())\nmethod. Then, send the ID token to your app's backend. On the backend, verify\nthe token using either a Google API client library or a general-purpose JWT\nlibrary.\n\nBefore you begin\n\n- Your app must be able to successfully [retrieve a user's credentials](/identity/smartlock-passwords/android/retrieve-credentials#handle_successful_credential_requests) or [retrieve a sign-in hint](/identity/smartlock-passwords/android/retrieve-hints).\n- You must call `setAccountTypes(IdentityProviders.GOOGLE)` when you build the `CredentialRequest` and `HintRequest` objects.\n\nGet an ID token from the Credentials object\n\nAfter you retrieve a user's credentials, check if the `Credentials` object\nincludes an ID token. If it does, call `getIdTokens` to retrieve it, and send it\nto your backend by HTTPS POST. \n\n if (!credential.getIdTokens().isEmpty()) {\n String idToken = credential.getIdTokens().get(0).getIdToken();\n\n HttpClient httpClient = new DefaultHttpClient();\n HttpPost httpPost = new HttpPost(\"https://yourbackend.example.com/tokensignin\");\n\n try {\n List nameValuePairs = new ArrayList(1);\n nameValuePairs.add(new BasicNameValuePair(\"idToken\", idToken));\n httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));\n\n HttpResponse response = httpClient.execute(httpPost);\n int statusCode = response.getStatusLine().getStatusCode();\n final String responseBody = EntityUtils.toString(response.getEntity());\n Log.i(TAG, \"Signed in as: \" + responseBody);\n }\n }\n\nVerify the ID token on the backend\n\nAfter you receive the ID token by HTTPS POST, you must verify the token's\nsignature, and verify the token's `aud`, `iss`, and `exp` claims.\n\nThe `aud` claim of an ID token from Smart Lock for Passwords has the following\nformat: \n\n```\nandroid://SHA512_HASH@ANDROID_PACKAGE_NAME\n```\n\n\u003cbr /\u003e\n\nThe value \u003cvar translate=\"no\"\u003eSHA512\u003cem\u003eHASH\u003c/em\u003e\u003c/var\u003e*is the SHA-512 hash of your signing\ncertificate. You can get this value using the `keytool` and `openssl` utilities:* \n\n```\nkeytool -exportcert -keystore \u003cvar translate=\"no\"\u003epath-to-keystore\u003c/var\u003e -alias \u003cvar translate=\"no\"\u003ekey-name\u003c/var\u003e \n\n | openssl sha -sha512 -binary \n\n | base64 -w 0 \n\n | tr '+/' '-'\n```\n\n\u003cbr /\u003e\n\n| **Note:** On Mac OS X, omit the `-w 0` parameter from the `base64` command.\n\nOr, you can get the SHA-512 hash by examining an ID token you know to be valid.\n\nJWT libraries can handle some of these verification tasks for you. For example,\nusing the [Google Auth Library for Java](https://github.com/googleapis/google-auth-library-java): \n\n import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;\n import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;\n import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;\n\n ...\n\n // Verifier that checks that the token has the proper issuer and audience,\n // and hasn't expired\n private static GoogleIdTokenVerifier verifier =\n new GoogleIdTokenVerifier.Builder(transport, jsonFactory)\n .setAudience(Arrays.asList(String.format(\"android://%s@%s\", SHA512_HASH, PACKAGE_NAME)))\n .build();\n\n // (Receive idTokenString by HTTPS POST)\n\n GoogleIdToken idToken = verifier.verify(idTokenString);\n if (idToken != null) {\n Payload payload = idToken.getPayload();\n System.out.println(\"User email: \" + payload.getEmail());\n if (payload.getEmailVerified()) {\n System.out.println(\"Email verified by Google.\");\n }\n } else {\n System.out.println(\"Invalid ID token.\");\n }\n\nSee the [Google Sign-In documentation](/identity/sign-in/android/backend-auth#using-a-google-api-client-library)\nfor more details."]]