diff --git a/gradle.properties b/gradle.properties index cc138ce..8794fdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,4 +20,4 @@ kotlin.mpp.enableCInteropCommonization=true #Development development=true -kmpAuthVersion=2.3.0 \ No newline at end of file +kmpAuthVersion=2.3.1 \ No newline at end of file diff --git a/kmpauth-firebase/api/android/kmpauth-firebase.api b/kmpauth-firebase/api/android/kmpauth-firebase.api index 2269db4..77d6b96 100644 --- a/kmpauth-firebase/api/android/kmpauth-firebase.api +++ b/kmpauth-firebase/api/android/kmpauth-firebase.api @@ -29,7 +29,7 @@ public final class com/mmk/kmpauth/firebase/github/GithubButtonUiContainerKt { public final class com/mmk/kmpauth/firebase/google/GoogleButtonUiContainerFirebaseKt { public static final fun GoogleButtonUiContainerFirebase (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V - public static final fun GoogleButtonUiContainerFirebase (Landroidx/compose/ui/Modifier;ZZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V + public static final fun GoogleButtonUiContainerFirebase (Landroidx/compose/ui/Modifier;ZZLjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V } public final class com/mmk/kmpauth/firebase/oauth/OAuthContainer_androidKt { diff --git a/kmpauth-firebase/api/jvm/kmpauth-firebase.api b/kmpauth-firebase/api/jvm/kmpauth-firebase.api index 5dcce1d..d02e67b 100644 --- a/kmpauth-firebase/api/jvm/kmpauth-firebase.api +++ b/kmpauth-firebase/api/jvm/kmpauth-firebase.api @@ -29,7 +29,7 @@ public final class com/mmk/kmpauth/firebase/github/GithubButtonUiContainerKt { public final class com/mmk/kmpauth/firebase/google/GoogleButtonUiContainerFirebaseKt { public static final fun GoogleButtonUiContainerFirebase (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V - public static final fun GoogleButtonUiContainerFirebase (Landroidx/compose/ui/Modifier;ZZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V + public static final fun GoogleButtonUiContainerFirebase (Landroidx/compose/ui/Modifier;ZZLjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V } public final class com/mmk/kmpauth/firebase/oauth/OAuthContainer_jvmKt { diff --git a/kmpauth-firebase/src/commonMain/kotlin/com/mmk/kmpauth/firebase/google/GoogleButtonUiContainerFirebase.kt b/kmpauth-firebase/src/commonMain/kotlin/com/mmk/kmpauth/firebase/google/GoogleButtonUiContainerFirebase.kt index 4370a1e..829bed4 100644 --- a/kmpauth-firebase/src/commonMain/kotlin/com/mmk/kmpauth/firebase/google/GoogleButtonUiContainerFirebase.kt +++ b/kmpauth-firebase/src/commonMain/kotlin/com/mmk/kmpauth/firebase/google/GoogleButtonUiContainerFirebase.kt @@ -19,6 +19,9 @@ import kotlinx.coroutines.launch * Child of this Composable can be any view or Composable function. * You need to call [UiContainerScope.onClick] function on your child view's click function. * + * @param linkAccount Default value is false + * @param filterByAuthorizedAccounts set to true so users can choose between available accounts to sign in. + * @param scopes Custom scopes to retrieve more information. Default value listOf("email", "profile") * [onResult] callback will return [Result] with [FirebaseUser] type. * * Example Usage: @@ -36,6 +39,7 @@ public fun GoogleButtonUiContainerFirebase( modifier: Modifier = Modifier, linkAccount: Boolean = false, filterByAuthorizedAccounts: Boolean = false, + scopes: List = listOf("email", "profile"), onResult: (Result) -> Unit, content: @Composable UiContainerScope.() -> Unit, ) { @@ -45,6 +49,7 @@ public fun GoogleButtonUiContainerFirebase( GoogleButtonUiContainer( modifier = modifier, filterByAuthorizedAccounts = filterByAuthorizedAccounts, + scopes = scopes, onGoogleSignInResult = { googleUser -> val idToken = googleUser?.idToken val accessToken = googleUser?.accessToken diff --git a/kmpauth-google/api/android/kmpauth-google.api b/kmpauth-google/api/android/kmpauth-google.api index bdfb2a2..701bcb4 100644 --- a/kmpauth-google/api/android/kmpauth-google.api +++ b/kmpauth-google/api/android/kmpauth-google.api @@ -37,7 +37,7 @@ public final class com/mmk/kmpauth/google/GoogleAuthUiProvider$DefaultImpls { } public final class com/mmk/kmpauth/google/GoogleButtonUiContainerKt { - public static final fun GoogleButtonUiContainer (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V + public static final fun GoogleButtonUiContainer (Landroidx/compose/ui/Modifier;ZLjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V } public final class com/mmk/kmpauth/google/GoogleUser { diff --git a/kmpauth-google/api/jvm/kmpauth-google.api b/kmpauth-google/api/jvm/kmpauth-google.api index bdfb2a2..701bcb4 100644 --- a/kmpauth-google/api/jvm/kmpauth-google.api +++ b/kmpauth-google/api/jvm/kmpauth-google.api @@ -37,7 +37,7 @@ public final class com/mmk/kmpauth/google/GoogleAuthUiProvider$DefaultImpls { } public final class com/mmk/kmpauth/google/GoogleButtonUiContainerKt { - public static final fun GoogleButtonUiContainer (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V + public static final fun GoogleButtonUiContainer (Landroidx/compose/ui/Modifier;ZLjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V } public final class com/mmk/kmpauth/google/GoogleUser { diff --git a/kmpauth-google/kmpauth_google.podspec b/kmpauth-google/kmpauth_google.podspec index b71a01a..a0b5dcf 100644 --- a/kmpauth-google/kmpauth_google.podspec +++ b/kmpauth-google/kmpauth_google.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'kmpauth_google' - spec.version = '2.3.0' + spec.version = '2.3.1' spec.homepage = '' spec.source = { :http=> ''} spec.authors = '' diff --git a/kmpauth-google/src/androidMain/kotlin/com/mmk/kmpauth/google/GoogleAuthUiProviderImpl.kt b/kmpauth-google/src/androidMain/kotlin/com/mmk/kmpauth/google/GoogleAuthUiProviderImpl.kt index 45368dd..3305681 100644 --- a/kmpauth-google/src/androidMain/kotlin/com/mmk/kmpauth/google/GoogleAuthUiProviderImpl.kt +++ b/kmpauth-google/src/androidMain/kotlin/com/mmk/kmpauth/google/GoogleAuthUiProviderImpl.kt @@ -1,7 +1,6 @@ package com.mmk.kmpauth.google import android.content.Context -import androidx.credentials.Credential import androidx.credentials.CredentialManager import androidx.credentials.CustomCredential import androidx.credentials.GetCredentialRequest @@ -32,23 +31,40 @@ internal class GoogleAuthUiProviderImpl( getGoogleUserFromCredential(filterByAuthorizedAccounts = filterByAuthorizedAccounts) } catch (e: NoCredentialException) { - if (!filterByAuthorizedAccounts) return handleCredentialException(e) + if (!filterByAuthorizedAccounts) + return handleCredentialException( + e = e, + filterByAuthorizedAccounts = filterByAuthorizedAccounts, + scopes = scopes + ) try { getGoogleUserFromCredential(filterByAuthorizedAccounts = false) } catch (e: GetCredentialException) { - handleCredentialException(e) + handleCredentialException( + e = e, + filterByAuthorizedAccounts = filterByAuthorizedAccounts, + scopes = scopes + ) } catch (e: NullPointerException) { null } } catch (e: GetCredentialException) { - handleCredentialException(e) + handleCredentialException( + e = e, + filterByAuthorizedAccounts = filterByAuthorizedAccounts, + scopes = scopes + ) } catch (e: NullPointerException) { null } return googleUser } - private suspend fun handleCredentialException(e: GetCredentialException): GoogleUser? { + private suspend fun handleCredentialException( + e: GetCredentialException, + filterByAuthorizedAccounts: Boolean, + scopes: List + ): GoogleUser? { println("GoogleAuthUiProvider error: ${e.message}") val shouldCheckLegacyAuthServices = when (e) { is GetCredentialProviderConfigurationException -> true @@ -57,15 +73,21 @@ internal class GoogleAuthUiProviderImpl( else -> false } return if (shouldCheckLegacyAuthServices) { - checkLegacyGoogleSignIn() + checkLegacyGoogleSignIn(filterByAuthorizedAccounts, scopes) } else { null } } - private suspend fun checkLegacyGoogleSignIn(): GoogleUser? { + private suspend fun checkLegacyGoogleSignIn( + filterByAuthorizedAccounts: Boolean, + scopes: List + ): GoogleUser? { println("GoogleAuthUiProvider: Checking Outdated Google Sign In...") - return googleLegacyAuthentication.signIn() + return googleLegacyAuthentication.signIn( + filterByAuthorizedAccounts = filterByAuthorizedAccounts, + scopes = scopes + ) } private suspend fun getGoogleUserFromCredential(filterByAuthorizedAccounts: Boolean): GoogleUser? { diff --git a/kmpauth-google/src/commonMain/kotlin/com/mmk/kmpauth/google/GoogleButtonUiContainer.kt b/kmpauth-google/src/commonMain/kotlin/com/mmk/kmpauth/google/GoogleButtonUiContainer.kt index 34ab272..0070125 100644 --- a/kmpauth-google/src/commonMain/kotlin/com/mmk/kmpauth/google/GoogleButtonUiContainer.kt +++ b/kmpauth-google/src/commonMain/kotlin/com/mmk/kmpauth/google/GoogleButtonUiContainer.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Modifier import com.mmk.kmpauth.core.UiContainerScope +import com.mmk.kmpauth.google.GoogleAuthUiProvider.Companion.BASIC_AUTH_SCOPE import kotlinx.coroutines.launch /** @@ -32,12 +33,14 @@ import kotlinx.coroutines.launch * ``` * * @param filterByAuthorizedAccounts set to true so users can choose between available accounts to sign in. + * @param scopes Custom scopes to retrieve more information. Default value listOf("email", "profile") * setting to false list any accounts that have previously been used to sign in to your app. */ @Composable public fun GoogleButtonUiContainer( modifier: Modifier = Modifier, filterByAuthorizedAccounts: Boolean = false, + scopes: List = BASIC_AUTH_SCOPE, onGoogleSignInResult: (GoogleUser?) -> Unit, content: @Composable UiContainerScope.() -> Unit, ) { @@ -51,7 +54,10 @@ public fun GoogleButtonUiContainer( override fun onClick() { println("GoogleUiButtonContainer is clicked") coroutineScope.launch { - val googleUser = googleAuthUiProvider.signIn(filterByAuthorizedAccounts) + val googleUser = googleAuthUiProvider.signIn( + filterByAuthorizedAccounts = filterByAuthorizedAccounts, + scopes = scopes + ) updatedOnResultFunc(googleUser) } }