This repository demonstrates the implementation of One Tap Google Sign-In using Jetpack Compose in an Android app. The project utilizes the stevdza-san dependency for easy integration of Google sign-in functionality.
- One Tap Google Sign-In using Jetpack Compose
- Customizable UI for the sign-in button
- Easy retrieval of Google user information
-
Google Cloud Platform Setup:
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to APIs & Services > Credentials.
- Create an OAuth 2.0 Client ID and add your app's SHA-1 fingerprint.
- Copy the Client ID and replace the
YOUR CLIENT IDplaceholder in the code with your Client ID.
-
Gradle:
-
Dependencies: This project uses the
stevdza-sandependency for One Tap Google Sign-In. Make sure to include it in yourbuild.gradlefile:dependencies { implementation("com.github.stevdza-san:OneTapCompose:1.0.14") }-
- settings.gradle:
dependencyResolutionManagement { repositories { ... maven(url = "https://jitpack.io") } } -
-
-
Usage
Replace
YOUR CLIENT IDwith the client ID you copied from Google Cloud:val state = rememberOneTapSignInState() var user: GoogleUser? by remember { mutableStateOf(null) } OneTapSignInWithGoogle( state = state, clientId = "YOUR CLIENT ID", // Replace with your client ID rememberAccount = false, onTokenIdReceived = { user = getUserFromTokenId(tokenId = it) Log.d("MainActivity", user.toString()) }, onDialogDismissed = { Log.d("MainActivity", it) } ) Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { Button(onClick = { state.open() }) { Row(verticalAlignment = Alignment.CenterVertically) { if (state.opened) { CircularProgressIndicator( color = Color.White ) } Spacer(modifier = Modifier.width(8.dp)) Text(text = "Sign in") } } }
-
Clone the repository:
git clone https://github.com/Bhavyansh03-tech/One_Tap_Google_Sign_In.git
-
Open the project in Android Studio.
-
Replace the YOUR CLIENT ID in the MainActivity.kt file with your actual Google Client ID from the Google Cloud Console.
-
Build and run the project on your Android device or emulator.
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin feature/your-feature). - Create a new Pull Request.
For questions or feedback, please contact @Bhavyansh03-tech.