Skip to main content

Sign in with Google

This guide teaches you how to add native Sign in with Google to your Clerk apps on Android platforms. This native flow differs from Google OAuth. See the Google OAuth setup guide.

From your Android project's root directory, run the Clerk CLI with npx and choose to enable native Sign in with Google:

terminal
npx clerk@latest init

The CLI registers your native app, enables Native API, and enables Google for sign-up and sign-in on the linked development instance. To add Google sign-in after an earlier setup, run npx clerk@latest init --sign-in-with-google.

The Clerk Android SDK passes your Google connection's Web client ID to Credential Manager as the server client ID, so the connection needs its own Google Web client rather than Clerk's shared development credentials. When the connection doesn't have one yet, the CLI prints the Google Cloud steps with your package name, your debug certificate's SHA-1, and Clerk's redirect URI, then asks for the Web client's Client ID and Client Secret. You can also pass --google-client-id and --google-client-secret-file, which accepts a file holding the secret, the client's JSON download from the Google Cloud Console, or - for standard input. The secret is never accepted as a command argument. A connection that already has a Web client keeps it.

The CLI can't create the Google Cloud clients for you. Create the Android client and the Web client as described in the manual steps below, using the values the CLI prints. Nothing in your app changes for Google: the SDK's own manifest handles the OAuth redirect.

Afterward, run clerk doctor to check the Clerk side. It reports whether the Google connection is enabled for authentication and whether it has a Web client ID, and reminds you that Google Cloud needs an Android client for your package name and each signing certificate's SHA-1, which it can't verify.

Configure manually

To make the setup process easier, it's recommended to keep two browser tabs open - one for the Clerk Dashboard and one for your Google Cloud Console.

Enable Google as a social connection

  1. In the Clerk Dashboard, navigate to the SSO connections page.
  2. Select Add connection and select For all users.
  3. Select Google from the provider list.
  4. Ensure that both Enable for sign-up and sign-in and Use custom credentials are toggled on.
  5. Save the Authorized Redirect URI somewhere secure. Keep this page open.

Create the Google Developer Android client

  1. Navigate to the Google Cloud Console.
  2. Select an existing project or create a new one. You'll be redirected to your project's Dashboard page.
  3. In the top-left, select the menu icon (≡) and select APIs & Services. Then, select Credentials.
  4. Next to Credentials, select Create Credentials. Then, select OAuth client ID. You might need to configure your OAuth consent screen. Otherwise, you'll be redirected to the Create OAuth client ID page.
  5. For the Application type, select Android.
  6. Complete the required fields.
    • Package name: Your package name is in your build.gradle file, formatted as com.example.myclerkapp.

    • SHA-1 certificate fingerprint: To get your SHA-1, run the following command in your terminal:

      Important

      Replace path-to-debug-or-production-keystore with the path to your debug or production keystore. By default, the debug keystore is located in ~/.android/debug.keystore. It may ask for a keystore password, which is android. You may need to install OpenJDK to run the keytool command.

      terminal
      keytool -keystore path-to-debug-or-production-keystore -list -v
  7. Select Create.

Create the Google Developer Web client

  1. In the same project, create another client. Next to Credentials, select Create Credentials. Then, select OAuth client ID.
  2. For the Application type, select Web Application.
  3. Complete the required fields. In the Authorized Redirect URIs setting, paste the Authorized Redirect URI value you saved from the Clerk Dashboard.
  4. Select Create. A modal will open with your Client ID and Client Secret. Save these values somewhere secure.

Set the Client ID and Client Secret in the Clerk Dashboard

  1. Navigate back to the Clerk Dashboard where the configuration page should still be open. Paste the Client ID and Client Secret values that you saved into the respective fields.
  2. Select Save.

Note

If the page is no longer open, navigate to the SSO connections page in the Clerk Dashboard. Select the connection. Under Use custom credentials, paste the values into their respective fields.

The simplest way to test your connection is to visit your Clerk app's Account Portal, which is available for all Clerk apps out-of-the-box.

  1. In the Clerk Dashboard, navigate to the Account Portal page.
  2. Next to Sign-in, select the button to visit the sign-in page. The URL should resemble:
    • For development - https://your-domain.accounts.dev/sign-in
    • For production - https://accounts.your-domain.com/sign-in
  3. Sign in with your connection's credentials.

If sign-in fails, check Application Logs for an oauth_callback.failed event. Its details include the failure reason and may include an error message.

Configure your production instance

clerk init configures only the linked development instance. Before releasing, deploy your Clerk app to production, enable the Native API on the production instance, and register your release app's package name and signing certificate's SHA-256 fingerprint on the Native applications page.

Configure the production Google connection with a Web client authorized for that instance's redirect URI. In Google Cloud, create an Android client for the release package name and each signing certificate's SHA-1 fingerprint. Use the production in your release build, then build and test native Sign in with Google.

Usage

To learn how to build a sign-up and sign-in flow that supports OAuth connections in your Android application, see the custom flow guide.

Feedback

What did you think of this content?

Last updated on