Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide google auth option, if GoogleApi doesn't available on device #72

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ val appModule = module {

factory { AgreementProvider(get(), get()) }
factory { FacebookAuthHelper() }
factory { GoogleAuthHelper(get()) }
factory { GoogleAuthHelper(get(), get()) }
factory { MicrosoftAuthHelper() }
factory { OAuthHelper(get(), get(), get()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SignInViewModel(
private val _uiState = MutableStateFlow(
SignInUIState(
isFacebookAuthEnabled = config.getFacebookConfig().isEnabled(),
isGoogleAuthEnabled = config.getGoogleConfig().isEnabled(),
isGoogleAuthEnabled = config.getGoogleConfig().isEnabled() && oAuthHelper.isGoogleAuthEnabled(),
isMicrosoftAuthEnabled = config.getMicrosoftConfig().isEnabled(),
isSocialAuthEnabled = config.isSocialAuthEnabled(),
isLogistrationEnabled = config.isPreLoginExperienceEnabled(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SignUpViewModel(
private val _uiState = MutableStateFlow(
SignUpUIState(
isFacebookAuthEnabled = config.getFacebookConfig().isEnabled(),
isGoogleAuthEnabled = config.getGoogleConfig().isEnabled(),
isGoogleAuthEnabled = config.getGoogleConfig().isEnabled() && oAuthHelper.isGoogleAuthEnabled(),
isMicrosoftAuthEnabled = config.getMicrosoftConfig().isEnabled(),
isSocialAuthEnabled = config.isSocialAuthEnabled(),
isLoading = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openedx.auth.presentation.sso

import android.accounts.Account
import android.app.Activity
import android.content.Context
import android.credentials.GetCredentialException
import android.os.Bundle
import androidx.annotation.WorkerThread
Expand All @@ -11,6 +12,8 @@ import androidx.credentials.CustomCredential
import androidx.credentials.GetCredentialRequest
import androidx.credentials.exceptions.GetCredentialCancellationException
import com.google.android.gms.auth.GoogleAuthUtil
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException
Expand All @@ -19,7 +22,7 @@ import org.openedx.auth.domain.model.SocialAuthResponse
import org.openedx.core.config.Config
import org.openedx.core.utils.Logger

class GoogleAuthHelper(private val config: Config) {
class GoogleAuthHelper(private val context: Context, private val config: Config) {

private val logger = Logger(TAG)

Expand Down Expand Up @@ -103,6 +106,9 @@ class GoogleAuthHelper(private val config: Config) {
}
}

fun isGoogleAuthEnabled() =
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS

private companion object {
const val TAG = "GoogleAuthHelper"
const val SCOPE = "oauth2: https://www.googleapis.com/auth/userinfo.email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class OAuthHelper(
}
}

internal fun isGoogleAuthEnabled() = googleAuthHelper.isGoogleAuthEnabled()

fun clear() {
facebookAuthHelper.clear()
}
Expand Down
Loading