Search code examples
google-signincredential-managerandroid-credential-managersign-in-with-google

Android Credential Manager: what's the differences between GetSignInWithGoogleOption and GetGoogleIdOption


When Authenticate users with Sign in with Google, the official document says "To trigger the Sign in with Google button flow, use GetSignInWithGoogleOption instead of GetGoogleIdOption", can someone helps to explain what's the meaning of this? What's the differences between GetSignInWithGoogleOption and GetGoogleIdOption and when should I use GetSignInWithGoogleOption. Thanks

I tried both GetSignInWithGoogleOption and GetGoogleIdOption. When using GetSignInWithGoogleOption, the UI shown to the user is different; instead of a bottomsheet, it's a regular dialog. What's more , GetSignInWithGoogleOption allows add another account. But any other differences?


Solution

  • Here are some differences:

    • The SiwG Button flow opens a dialog while the other one opens a bottomsheet, as you had noticed.
    • The SiwG Button flow is recommended to be initiated when user taps on a "Sign-in with Google" button that you can add to your "Sign-in" page. The bottomsheet flow, however, is recommended to be started programmatically as son as a user opens your app (or lands on a page that provides a different experience if user is signed-in).
    • The SiwG Button flow lists all Google accounts on the device, even if a user is signed-out of an account (for example if user has changed their password for that account from a different surface). Selecting such an account will initiate the "re-authentication" flow. The bottomsheet flow only lists Google accounts that are signed-in. The reason for the difference in behavior is that the bottomsheet flow is supposed to be a very quick, almost a "one-tap" flow.
    • The SiwG button flow allows users to add a new Google account and if there are no Google accounts on the device to begin with, it automatically launches the Add Account flow. The bottomsheet flow doesn't do those; if there are no accounts, it returns an exception. The reason for this difference is that if developers follow our recommendation and initiate the button flow only if user taps on a "Sign-in with Google" button versus the automatica launch, then the button flow clearly indicates that the user is interested in signing in with a Google account, so the additional features are provided to help with that, while the bottomsheet flow pops up for the user without any explicit action from their side, hence we need to be more conservative in what we offer.
    • The API that launches the bottomsheet allows developers to possibly include other types of credentials, such as username/passwords or Passkeys (and in Android 14+, those can be sourced from other Password Managers); the SiwG button flow is restricted to showing only Google accounts.

    There are some more subtle differences that I don't get into them here. Also note that our recommendation is to show the bottomsheet flow for all types of credentials that your app supports when user opens the app, and also add the 'Sign-in with Google" button to your sign-in page so if, say, user closes the bottomsheet accidentally, they still have a way to sign-in using their Google accounts.