androidkotlinandroid-jetpack-composecredential-manager

CredentialManager with GoogleId always "cancelled"


Whichever way I implement compose credential manager, I get an exception GetCredentialCancellationException: activity is canceled by the user.

The manager shows a dialog with my Google accounts, I choose one and then there is a "consent screen" with a "continue as me" button. After clicking that, I get the exception above.

I don't know what I am doing wrong.

My libraries:
androidx.credentials.credentials:credentials:1.2.0-beta03
androidx.credentials.credentials:credentials-play-services-auth:1.2.0-beta03
com.google.android.gms:play-services-auth:20.7.0

The basic demo code:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)

        lifecycleScope.launch {
            CredentialManager.create(this@MainActivity.applicationContext).getCredential(
                context = this@MainActivity,
                request = GetCredentialRequest(
                    listOf(
                        GetGoogleIdOption.Builder()
                            .setFilterByAuthorizedAccounts(false)
                            .setAutoSelectEnabled(false)
                            .setServerClientId("secret-id")
                            .build(),
                    )
                ),
            ).credential
        }

        setContent {
            Text("DEMO")
        }
    }
}

Solution

  • Okay, finally figured it out after x days. The exception is wrong, it has nothing to do with the problem.

    I had wrong client id. It is not supposed to be Android client id, but WebApplication client id.

    I found it out after checking if google sign in via firebase would work and it was clearly written there, in step 1, point b. https://firebase.google.com/docs/auth/android/google-signin#authenticate_with_firebase