Stay organized with collections
Save and categorize content based on your preferences.
Google Identity Services (GIS) is a new set of APIs that provides users easy and
secure sign-in and sign-up, in an easy-to-implement package for developers.
This document details a new Google sign in API (part of GIS) that can be used to
start the sign-in or sign-up flow when a user taps on a "Sign-In with Google"
button. This API can be used instead of the existing Google Sign-In APIs for
sign in flows.
You should use this API only when the user explicitly shows intent to sign in
with Google. For example, use this API when they click a "Sign in with Google"
button in your app.
You should not use this API to prompt the user to sign-in on app launch or in
response to another trigger such as adding an item to the shopping cart. For
these use cases, use
One Tap sign-in and sign-up.
When you start the Google Sign-In flow with the new API, it will display this
UI:
To launch a Google Sign-In flow using the Identity API build a
GetSignInRequest object. Then, on a SignInClient object call
getSignInIntent. This call is async and on success it will provide a
PendingIntent to launch the dialog.
In onActivityResult retrieve a SignInCredential. The SignInCredential
object returned from getSignInCredentialFromIntent contains information
about a valid login. If the user fails to log in for some reason, an
ApiException is thrown.
privateActivityResultLauncher<IntentSenderRequest>loginResultHandler=registerForActivityResult(newActivityResultContracts.StartIntentSenderForResult(),result->{// handle intent result here});
The result of a successful sign in always returns the users full name, email,
and profile picture url. If you need additional information you can direct users
into a complete profile information flow.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003eGoogle Identity Services (GIS) offers a new, streamlined API for easy and secure user sign-in and sign-up within Android apps.\u003c/p\u003e\n"],["\u003cp\u003eThis new API is recommended for new apps, replacing the existing Google Sign-In API for most cases, except when authorization, server-side access, or custom OAuth scopes are required.\u003c/p\u003e\n"],["\u003cp\u003eThe API should be used only when a user explicitly initiates sign-in, such as clicking a "Sign in with Google" button, and not for automatic prompts on app launch or other triggers.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can build a \u003ccode\u003eGetSignInIntentRequest\u003c/code\u003e, use \u003ccode\u003eSignInClient\u003c/code\u003e to get a \u003ccode\u003ePendingIntent\u003c/code\u003e, and launch the sign-in flow; results are handled in \u003ccode\u003eonActivityResult\u003c/code\u003e with successful logins providing a \u003ccode\u003eSignInCredential\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful sign-in, developers receive the user's full name, email, and profile picture URL; additional user information can be collected through a separate profile completion flow.\u003c/p\u003e\n"]]],[],null,["Google Identity Services (GIS) is a new set of APIs that provides users easy and\nsecure sign-in and sign-up, in an easy-to-implement package for developers.\nThis document details a new Google sign in API (part of GIS) that can be used to\nstart the sign-in or sign-up flow when a user taps on a \"Sign-In with Google\"\nbutton. This API can be used instead of the existing Google Sign-In APIs for\nsign in flows.\n| **Note:** Google Identity Services will eventually replace the existing Google Sign-In API. For new apps we recommend using Google Identity Services instead of the Google Sign-In API for sign-in and sign-up, unless you need authorization, [Server-Side Access](https://developers.google.com/identity/sign-in/android/offline-access), or custom OAuth scopes. These features are coming in future versions of Google Identity Services.\n\nYou should use this API only when the user explicitly shows intent to sign in\nwith Google. For example, use this API when they click a \"Sign in with Google\"\nbutton in your app.\n\nYou should not use this API to prompt the user to sign-in on app launch or in\nresponse to another trigger such as adding an item to the shopping cart. For\nthese use cases, use\n[One Tap sign-in and sign-up](https://developers.google.com/identity/one-tap/android/legacy-get-started).\n\nWhen you start the Google Sign-In flow with the new API, it will display this\nUI:\n\nBefore you begin\n\n[Configure a Google API Console project and set up your Android Studio project](https://developers.google.com/identity/sign-in/android/legacy-start-integrating).\n\nMake a sign-in request\n\nTo launch a Google Sign-In flow using the Identity API build a\n`GetSignInRequest` object. Then, on a `SignInClient` object call\n`getSignInIntent`. This call is async and on success it will provide a\n`PendingIntent` to launch the dialog. \n\n private static final int REQUEST_CODE_GOOGLE_SIGN_IN = 1; /* unique request id */\n\n private void signIn() {\n GetSignInIntentRequest request =\n GetSignInIntentRequest.builder()\n .setServerClientId(getString(R.string.server_client_id))\n .build();\n\n Identity.getSignInClient(activity)\n .getSignInIntent(request)\n .addOnSuccessListener(\n result -\u003e {\n try {\n startIntentSenderForResult(\n result.getIntentSender(),\n REQUEST_CODE_GOOGLE_SIGN_IN,\n /* fillInIntent= */ null,\n /* flagsMask= */ 0,\n /* flagsValue= */ 0,\n /* extraFlags= */ 0,\n /* options= */ null);\n } catch (IntentSender.SendIntentException e) {\n Log.e(TAG, \"Google Sign-in failed\");\n }\n })\n .addOnFailureListener(\n e -\u003e {\n Log.e(TAG, \"Google Sign-in failed\", e);\n });\n }\n\nHandle sign in results\n\nIn `onActivityResult` retrieve a `SignInCredential`. The `SignInCredential`\nobject returned from `getSignInCredentialFromIntent` contains information\nabout a valid login. If the user fails to log in for some reason, an\n`ApiException` is thrown. \n\n @Override\n public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n if(resultCode == Activity.RESULT_OK) {\n if (requestCode == REQUEST_CODE_GOOGLE_SIGN_IN) {\n try {\n SignInCredential credential = Identity.getSignInClient(this).getSignInCredentialFromIntent(data);\n // Signed in successfully - show authenticated UI\n updateUI(credential);\n } catch (ApiException e) {\n // The ApiException status code indicates the detailed failure reason.\n }\n }\n }\n }\n\n**Note:** Consider using the [Activity Result API](https://developer.android.com/training/basics/intents/result) to manage Activity callbacks. \n\n private ActivityResultLauncher\u003cIntentSenderRequest\u003e loginResultHandler = registerForActivityResult(new ActivityResultContracts.StartIntentSenderForResult(), result -\u003e {\n // handle intent result here\n });\n\nThe result of a successful sign in always returns the users full name, email,\nand profile picture url. If you need additional information you can direct users\ninto a complete profile information flow."]]