Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
stevdza-san committed Dec 18, 2023
2 parents fb070f9 + 61b9bfa commit 56b7d3b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 10 deletions.
78 changes: 70 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">One-Tap Sign in with Google</h1></br>

<p align="center">
<a href="https://jitpack.io/#stevdza-san/OneTapCompose/1.0.9"><img alt="License" src="https://badgen.net/badge/Jitpack/1.0.9/orange?icon=github"/></a>
<a href="https://jitpack.io/#stevdza-san/OneTapCompose/1.0.10"><img alt="License" src="https://badgen.net/badge/Jitpack/1.0.10/orange?icon=github"/></a>
<a href="https://github.com/stevdza-san"><img alt="Profile" src="https://badgen.net/badge/Github/stevdza_san/green?icon=github"/></a>
</p><br>

Expand All @@ -15,15 +15,15 @@ It hides all the boilerplate code away from you.
<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/OneTap2.gif" width="268"/>
</p>

## Download
<a href="https://jitpack.io/#stevdza-san/OneTapCompose/1.0.9"><img alt="License" src="https://badgen.net/badge/Jitpack/1.0.9/orange?icon=github"/></a>
# Download
<a href="https://jitpack.io/#stevdza-san/OneTapCompose/1.0.10"><img alt="License" src="https://badgen.net/badge/Jitpack/1.0.10/orange?icon=github"/></a>

### Gradle

Add the dependency below to your module's `build.gradle` file:
```gradle
dependencies {
implementation("com.github.stevdza-san:OneTapCompose:1.0.9")
implementation("com.github.stevdza-san:OneTapCompose:1.0.10")
}
```
Add a repository in your `settings.gradle` file:
Expand All @@ -35,7 +35,7 @@ dependencyResolutionManagement {
}
}
```
## Usage
# Usage

Before you can use this library, you need to create a new project on a <a href="https://cloud.google.com/">Google Cloud Platform</a>.
You need to create OAuth Client ID <i>(ANDROID & WEB)</i>, because you will need that same Client ID (WEB), in order to implement One-Tap Sign in with Google.
Expand Down Expand Up @@ -65,6 +65,8 @@ Button(onClick = { state.open() }) {
}
```

# Google User

And if you wish to extract a user information from a token id, that's now possible too! `getUserFromTokenId()` allows you to do exactly that. It returns a `GoogleUser` object, that contains lot's of different information related to that same user.

```kotlin
Expand All @@ -85,19 +87,79 @@ Available `GoogleUser` information:
- ExpirationTime
- Locale

## Release Build
# Sign in with Google Button

You can also use a drop-in opinionated button composable that works out of the box and encapsulates all the
sign in logic and follows Google's [Sign in with Google Branding Guidelines](https://developers.google.com/identity/branding-guidelines):

```kotlin
OneTapSignInWithGoogleButton(
clientId = "YOUR_CLIENT_ID"
)
```

According to the design guidelines, the button is available in 3 themes:
1. Dark
2. Light
3. Neutral

<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/ButtonDark.png" width="300"/>
<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/ButtonLight.png" width="300"/>
<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/ButtonNeutral.png" width="300"/>

You can customise the theme using the `theme` parameter in the composable:
```kotlin
OneTapSignInWithGoogleButton(
clientId = "YOUR_CLIENT_ID",
theme = GoogleButtonTheme.Neutral
)
```

The buttons are also available in icon-only mode for all the themes:

<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/IconButtonDark.png" width="100"/>
<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/IconButtonLight.png" width="100"/>
<img src="https://github.com/stevdza-san/OneTapCompose/blob/master/previews/IconButtonNeutral.png" width="100"/>

It can be activated using the `iconOnly` parameter in the composable:

```kotlin
OneTapSignInWithGoogleButton(
clientId = "YOUR_CLIENT_ID",
iconOnly = true
)
```

## Button API
| Name | Type | Description |
| ------------- | ------------- | ------------- |
| clientId | String | CLIENT ID (Web) of your project, that you can obtain from a Google Cloud Platform. |
| state | OneTapSignInState | One-Tap Sign in State. Can be used to detect whether the sign in operation has already been triggered. |
| rememberAccount | Boolean | Remember a selected account to sign in with, for an easier and quicker sign in process. |
| nonce | String? | Optional nonce that can be used when generating a Google Token ID |
| onTokenIdReceived | ((String) -> Unit)? | Lambda that will be triggered after a successful authentication. Returns a Token ID. |
| onUserReceived | ((String) -> Unit)? | This function returns a GoogleUser object using the received tokenId. |
| onDialogDismissed | ((String) -> Unit)? | Lambda that will be triggered when One-Tap dialog disappears. Returns a message in a form of a string. |
| iconOnly | Boolean | Whether the button should only show the Google logo. |
| theme | GoogleButtonTheme | Sets the button style to either be Light, Dark, or Neutral which is in accordance with the official Google design guidelines. |
| colors | ButtonColors | ButtonColors that will be used to resolve the colors for this button in different states. |
| border | BorderStroke? | the border to draw around the container of this button |
| shape | Shape | defines the shape of this button's container, border (when border is not null) |
| onClick | (() -> Unit)? | called when this button is clicked |

# Release Build
If you are planning on publishing your app, be sure to generate a release SHA-1 fingerprint, and create a new oAuth credentials on your Google Cloud Platform project.
Also when you upload your app on Play Console, you'll find there a section (`Release > Setup > App signing`) that will generate the release SHA-1 fingerprint. You take it and create another oAuth credential.

## Troubleshoot
# Troubleshoot
In some cases you may encounter <i>"Google Account not Found."</i> message inside `onDialogDismiss` lambda, even if you have already connected a Google account
on your Android Emulator. Android emulators are prone to that issues <i>(Not sure why and when that's gonna get fixed)</i>.
My suggestion in that case is to try and add a Google account on some other Android Emulator.
If that doesn't work either, then use a real device instead.

Also to debug your app better, check the logs and search for a `OneTapCompose` tag, it might contain additional information to help you out with your issue.

## Like what you see? :yellow_heart:
# Like what you see? :yellow_heart:
⭐ Give a star to this repository. <br />
☕ Buy me a coffee: https://ko-fi.com/stevdza_san

Expand Down
4 changes: 2 additions & 2 deletions onetap/src/main/java/com/stevdzasan/onetap/Buttons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import androidx.compose.ui.unit.dp
* @param onTokenIdReceived Lambda that will be triggered after a successful
* authentication. Returns a Token ID.
* @param onUserReceived This function returns a [GoogleUser] object using the received tokenId.
* @param onDialogDismissed Lambda that will be triggered when One-Tap dialog.
* disappears. Returns a message in a form of a string.
* @param onDialogDismissed Lambda that will be triggered when One-Tap dialog disappears.
* Returns a message in a form of a string.
* @param iconOnly Whether the button should only show the Google logo.
* @param theme Sets the button style to either be Light, Dark, or Neutral which is in accordance
* with the official Google design guidelines.
Expand Down
Binary file added previews/ButtonDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/ButtonLight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/ButtonNeutral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/IconButtonDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/IconButtonLight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/IconButtonNeutral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 56b7d3b

Please sign in to comment.