Mn2C
Mn2C

Reputation: 121

How to use Credential Manager flutter package to implement 'Sign-in with Google'

I'm trying to use credential_manager flutter package to implement 'Sign-in with Google' (for Android device only) and not able to get it to work successfully. I'm skipping the 'Password based credentials' and 'Passkey' parts for now and i'm not sure if that's causing the issue. The 'Usage' part of the documentation is not entirely clear, it says "Sign up using Google account and then you will be able to see the saved credentials in the app."

try{
    final GoogleIdTokenCredential credential = await credentialManager.saveGoogleCredential(
        useButtonFlow: false
      );

} on CredentialException catch (e) {
    // Handle the error
    print('Error saving Google credential: ${e.message}');
}
      

What does 'Sign up using google account..' mean? I assume it means the device is signed onto a google account outside my app beforehand, because nothing is mentioned about Sign-up in the docs. And I just call credentialManager.saveGoogleCredential() directly, but I'm getting a 'login failed' error in the console. The screen to select my google account appears, but nothing happens thereafter except the error. If i call

 await credentialManager.getCredentials(
      fetchOptions: credential_manager.FetchOptionsAndroid(googleCredential: true),
    );

I get 'No credentials found' error in console.

Although the docs on the native Android implementation of Credential Manager is more complete, I'm trying to avoid implementing native android/kotlin code as I have no experience with that. That could be a last resort as there is a pretty good YouTube guide done by someone.

I'm also using Firebase Auth for email/password login that I've already implemented, if anyone has advice on Credential Manager + Firebase Auth, that would be helpful too. Appreciate everyone's help, thanks!

Credential Manager flutter package

Upvotes: 1

Views: 418

Answers (1)

chan fook sheng
chan fook sheng

Reputation: 31

I got it working. Did you configure it ? For Sign In with Google, you need to update the "googleClientId" in the main.dart with the Web Client ID. You can refer to the Android Studio docs for this. I believe it should work when you follow the config part of the flutter plugin for Sign In for Google.

Upvotes: 2

Related Questions