Google SignIn Compose

Aseem Wangoo
ProAndroidDev
Published in
6 min readSep 28, 2021

--

Google SignIn Compose

Article here: https://flatteredwithflutter.com/google-signin-compose/

We will cover briefly:

  1. Integrating the Google SignIn
  2. MVVM architecture
  3. Using Moshi to send data
  4. (Optional) Check for the previously signed-in user

Note: This article assumes the reader knows about Jetpack Compose

Google SignIn Compose

Integrating the Google SignIn

Prerequisite: You need to have a project inside the GoogleCloudPlatform.

Before we start integrating, we copy the client id (as received from the Google Cloud Platform) and paste it inside our res->strings.xml

Note: See the video above

<string name="google_cloud_server_client_id">YOUR_ID</string>

Setup

  • Install the dependencies inside build.gradle of your app
implementation 'com.google.android.gms:play-services-auth:19.2.0'
  • We can now access the methods for signing in with Google. Let’s create a class (GoogleApiContract) that is responsible for calling the google APIs
  • This class extends from ActivityResultContract then we override the method createIntent

To configure Google Sign-In to request users' ID and basic profile information, create a GoogleSignInOptions object with the DEFAULT_SIGN_IN parameter. To request users' email addresses as well, create the GoogleSignInOptions object with the requestEmail option.

override fun createIntent(context: Context, input: Int?): Intent {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("YOUR_ID_HERE")
.requestEmail()
.build();
val intent = GoogleSignIn.getClient(context,gso)
return intent.signInIntent
}
  • Lastly, we override the method…

--

--