Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
El cliente de Acceso con One Tap recupera un token de ID de Google cuando el usuario selecciona una Cuenta de Google. Un token de ID es una aserción firmada de la identidad de un usuario que también contiene información básica del perfil del usuario, posiblemente una dirección de correo electrónico que Google verificó.
Cuando los tokens de ID estén disponibles, podrás usarlos para autenticarte de forma segura con el backend de tu app o para registrar automáticamente al usuario en una cuenta nueva sin necesidad de verificar su dirección de correo electrónico.
Para que un usuario acceda o se registre con un token de ID, envía el token al backend de tu app. En el backend, verifica el token con una biblioteca cliente de la API de Google o una biblioteca JWT de uso general. Si el usuario no accedió a tu app con esta Cuenta de Google antes, crea una cuenta nueva.
Si, de manera opcional, elegiste usar un nonce para evitar ataques de repetición, usa getNonce para enviarlo junto con el token de ID a tu servidor de backend y verifica el valor esperado. Te recomendamos que consideres usar un nonce para mejorar la seguridad de los usuarios.
Obtén un token de ID del objeto de credenciales
Después de recuperar las credenciales de un usuario, verifica si el objeto de credenciales
incluye un token de ID. Si es así, envíalo a tu backend.
Java
publicclassYourActivityextendsAppCompatActivity{// ...privatestaticfinalintREQ_ONE_TAP=2;// Can be any integer unique to the Activity.privatebooleanshowOneTapUI=true;// ...@OverrideprotectedvoidonActivityResult(intrequestCode,intresultCode,@NullableIntentdata){super.onActivityResult(requestCode,resultCode,data);switch(requestCode){caseREQ_ONE_TAP:try{SignInCredentialcredential=oneTapClient.getSignInCredentialFromIntent(data);StringidToken=credential.getGoogleIdToken();if(idToken!=null){// Got an ID token from Google. Use it to authenticate// with your backend.Log.d(TAG,"Got ID token.");}}catch(ApiExceptione){// ...}break;}}}
Kotlin
classYourActivity:AppCompatActivity(){// ...privatevalREQ_ONE_TAP=2// Can be any integer unique to the ActivityprivatevarshowOneTapUI=true// ...overridefunonActivityResult(requestCode:Int,resultCode:Int,data:Intent?){super.onActivityResult(requestCode,resultCode,data)when(requestCode){REQ_ONE_TAP->{try{valcredential=oneTapClient.getSignInCredentialFromIntent(data)validToken=credential.googleIdTokenwhen{idToken!=null->{// Got an ID token from Google. Use it to authenticate// with your backend.Log.d(TAG,"Got ID token.")}else->{// Shouldn't happen.Log.d(TAG,"No ID token!")}}}catch(e:ApiException){// ...}}}// ...}
El contenido y las muestras de código que aparecen en esta página están sujetas a las licencias que se describen en la Licencia de Contenido. Java y OpenJDK son marcas registradas de Oracle o sus afiliados.
Última actualización: 2025-07-27 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-07-27 (UTC)"],[],[],null,["# Authenticate with a backend using ID tokens\n\n| **Caution:** One Tap for Android is deprecated. To ensure the continued security and usability of your app, [migrate to\n| Credential Manager](/identity/sign-in/credential-manager). Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience.\n\nThe One Tap sign-in client retrieves a Google ID token when the user selects a\nGoogle Account. An ID token is a signed assertion of a user's identity that also\ncontains a user's basic profile information, possibly including an email address\nthat has been verified by Google.\n\nWhen ID tokens are available, you can use them to securely authenticate with\nyour app's backend, or to automatically sign up the user for a new account\nwithout the need to verify the user's email address.\n\nTo sign in or sign up a user with an ID token, send the token to your app's\nbackend. On the backend, verify the token using either a Google API client\nlibrary or a general-purpose JWT library. If the user hasn't signed in to your\napp with this Google Account before, create a new account.\n\nIf you've optionally chosen to use a nonce to help avoid replay attacks, use\n[getNonce](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetSignInIntentRequest#public-string-getnonce)\nto send it along with the ID Token to your backend server, and check for the\nexpected value. We recommend that you strongly consider using a nonce to\nimprove user safety and security.\n\nGet an ID token from the credentials object\n-------------------------------------------\n\nAfter you retrieve a user's credentials, check if the credentials object\nincludes an ID token. If it does, send it to your backend. \n\n### Java\n\n```java\npublic class YourActivity extends AppCompatActivity {\n\n // ...\n private static final int REQ_ONE_TAP = 2; // Can be any integer unique to the Activity.\n private boolean showOneTapUI = true;\n // ...\n\n @Override\n protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n\n switch (requestCode) {\n case REQ_ONE_TAP:\n try {\n SignInCredential credential = oneTapClient.getSignInCredentialFromIntent(data);\n String idToken = credential.getGoogleIdToken();\n if (idToken != null) {\n // Got an ID token from Google. Use it to authenticate\n // with your backend.\n Log.d(TAG, \"Got ID token.\");\n }\n } catch (ApiException e) {\n // ...\n }\n break;\n }\n }\n}\n```\n\n### Kotlin\n\n```kotlin\nclass YourActivity : AppCompatActivity() {\n\n // ...\n private val REQ_ONE_TAP = 2 // Can be any integer unique to the Activity\n private var showOneTapUI = true\n // ...\n\n override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n super.onActivityResult(requestCode, resultCode, data)\n\n when (requestCode) {\n REQ_ONE_TAP -\u003e {\n try {\n val credential = oneTapClient.getSignInCredentialFromIntent(data)\n val idToken = credential.googleIdToken\n when {\n idToken != null -\u003e {\n // Got an ID token from Google. Use it to authenticate\n // with your backend.\n Log.d(TAG, \"Got ID token.\")\n }\n else -\u003e {\n // Shouldn't happen.\n Log.d(TAG, \"No ID token!\")\n }\n }\n } catch (e: ApiException) {\n // ...\n }\n }\n }\n // ...\n}\n```"]]