Google sign in is DOWN for Android app - App Services User Auth

Hello all,

Our app’s google sign in is currently not working for a huge part of our user base. I have tried for days to get this thing working and i am fed up with fustration that i am unable to make this work.

I have a question for users with more experience … have you been able to successfully implement Sign in with Google for ALL your users ?

I have implemented login with both tokenID and authcode methods … but all trys end with unsuccessful errors.

  1. with google token ID :
AUTH_ERROR(realm::app::ServiceError:47): illegal base64 data at input byte 342

22:42:09
AUTH
	at io.realm.internal.network.NetworkRequest.onError(NetworkRequest.java:68)

22:42:09
AUTH
	at io.realm.internal.objectstore.OsJavaNetworkTransport.nativeHandleResponse(Native Method)

22:42:09
AUTH
	at io.realm.internal.objectstore.OsJavaNetworkTransport.handleResponse(OsJavaNetworkTransport.java:98)

22:42:09
AUTH
	at io.realm.internal.network.OkHttpNetworkTransport$1.run(OkHttpNetworkTransport.java:102)

22:42:09
AUTH
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)

22:42:09
AUTH
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)

22:42:09
AUTH
	at java.lang.Thread.run(Thread.java:1012)

or

crypto/rsa: verification error
  1. with google authCode
error exchanging access code with OAuth2 provider

Any help wil be much much appreciated because frankly after reading all forum threads and SO topics … i am frenkly running out of ideeas.

Code:

override fun onCreate(savedInstanceState: Bundle?) {
        // Start: signin with google
         val gso = GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
             //.requestIdToken("555172020768-kd9ggah2uum9dui095fb0es4r9icf0ug.apps.googleusercontent.com")
             .requestServerAuthCode("555172020768-kd9ggah2uum9dui095fb0es4r9icf0ug.apps.googleusercontent.com")
             //.requestIdToken("555172020768-5qa3i5u536svsahannl3k8q8at3l4dgq.apps.googleusercontent.com")
             .requestEmail()
            .build()


        val googleSignInClient = GoogleSignIn.getClient(this, gso)
        val resultLauncher: ActivityResultLauncher<Intent> =
            registerForActivityResult(ActivityResultContracts.StartActivityForResult())
            { result ->
                val task: Task<GoogleSignInAccount> =
                    GoogleSignIn.getSignedInAccountFromIntent(result.data)
                handleSignInResult(task)
            }
        // End: signin with google

        loginwithGoogleButton.setOnClickListener {
            loginWithGoogle(googleSignInClient,resultLauncher)
        }


    private fun loginWithGoogle(googleSignInClient:GoogleSignInClient, resultLauncher: ActivityResultLauncher<Intent>) {
        val signInIntent: Intent = googleSignInClient.signInIntent
        resultLauncher.launch(signInIntent)
    }


    private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
        showProgressDialog("Autentificare in curs!")
        try {
            if (completedTask.isSuccessful) {
                val account : GoogleSignInAccount? = completedTask.getResult(ApiException::class.java)
                val email: String? = account?.email
                val firstName = account?.givenName

                account?.serverAuthCode?.let { account.email?.let { it1 ->
                    account.givenName?.let { it2 ->
                        astaSaFie(it,
                            it1, it2
                        )
                    }
                } }


            } else {
                Log.e(
                    "AUTH", "Google Auth failed: "
                            + completedTask.exception.toString()
                )
                onLoginFailed("Google Auth failed:,${completedTask.exception.toString()}")

            }
        } catch (e: ApiException) {
            Log.w("AUTH", "Failed to log in with Google OAuth: " + e.message)
            onLoginFailed("Failed to log in with Google OAuth::,${e.message}")
        }
    }


 private fun astaSaFie(token:String, email: String, firstName: String){

       // val googleCredentials = Credentials.google(token, GoogleAuthType.ID_TOKEN)
        val googleCredentials = Credentials.google(token, GoogleAuthType.AUTH_CODE)

        try {
            val urlDecoded = java.util.Base64.getUrlDecoder().decode(token)
            Log.d("JWT", "URL Decoded: $urlDecoded")
        }catch (e:Exception){
            Log.d("JWT","e:$e")
        }

        try {
            val decoded = java.util.Base64.getDecoder().decode(token)
            Log.d("JWT", "Decoded: $decoded")
        } catch (e: Exception) {
            Log.d("JWT", "e: $e");
        } 

        try {
            val androidDecoded = android.util.Base64.decode(token, android.util.Base64.DEFAULT)
            Log.d("JWT", "Android Decoded DEFAULT: $androidDecoded")
        } catch (e: Exception) {
            Log.d("JWT", "e: $e");
        } 

        try {
            val urlAndroidDecoded = android.util.Base64.decode(token, android.util.Base64.URL_SAFE)
            Log.d("JWT", "Android Decoded URL_SAFE: $urlAndroidDecoded")
        } catch (e: Exception) {
            Log.d("JWT", "e: $e");
        } 

        taskApp?.loginAsync(googleCredentials) { it ->
            if (it.isSuccess) {
                Log.v(
                    "AUTH",
                    "Successfully logged in to MongoDB Realm using Google OAuth."
                )
                Helpers().setLoginSuccesfoul(this, true)
                Helpers().setAuthProvider(this,"google")

                //TODO: 1 are limite setate in cont? daca nu are inseamna ca este un user now daca da inseamana ca este un user vechi
                checkifAccountIsNeeded(email, firstName)

            } else {
                hideProgressDialog()
                onLoginFailed("Nu s-a putut crea contul,${it.error}")
                Log.e(
                    "AUTH",
                    "Failed to log in to MongoDB Realm: ", it.error
                )
            }
        }

    }

The above is my latest attempt using authcode insted of tokenid.

Any help will be greatly appreciated.

Best regards,
Andrei