CapacitorGoogleAuth: Android ClientId do not working, but Web ClientId do working

There are many comment about API Exception: 10

I think most important thing is SHA fingerprint. (Android app and google android client must have the same fingerprint.) So I copy SHA from ~/.android/debug.keystore

keytool -keystore ~/.android/debug.keystore -list -v

Also I can get SHA from android studio → gradle → tasks → android → signingReport image

copy SHA1 and past to android client. image

But it is not working ! why ?? (error : something went wrong)

I use capacitor3 and vue2 without firebase

below is my config about capacitor and MainActivity

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'com.example',
  appName: 'name',
  webDir: 'dist',
  bundledWebRuntime: false,
  server: {
    hostname: 'localhost:8080',
    url: 'http://192.168.0.21:8080/',
    cleartext: true,
  },
  plugins: {
    GoogleAuth: {
      androidClientId:
        'android-client-id',
      scopes: ['profile', 'email'],
      forceCodeForRefreshToken: false,
    },
  },
};

export default config;
package com.example;

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;


public class MainActivity extends BridgeActivity {
     @Override
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        registerPlugin(GoogleAuth.class);
     }
 }

Using Web client

If you used the Web ClientId, google signin is working.

So android type is not working but web application type is working

If you change only androidClientId to WebClient in the same setting as above, it will work.

GoogleAuth: {
      androidClientId:
        'web-client-id',
      scopes: ['profile', 'email'],
      forceCodeForRefreshToken: false,
    },

How Can I use AndroidClientId ? and why WebClient working good ?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (6 by maintainers)

Most upvoted comments

Finally, I figured out how to use android

For androidClientId in capacitor config, use the client id of the web application Also, To authenticate through the app’s sha-1 fingerprint, we also need to create an Android client. After creation, you need to put the app’s sha-1 in the Android client.(At this time, if you are using google console app signing, enter sha-1 in google console)

I don’t know how the web application client communicates with the android client either. However, as a result of testing, when using the above method, it worked well in both development and deployment environments.

Summary

  • Create both web application client and android client. (google cloud platform)
  • For capacitor, androidClientID : <web application client Id> should be used. (capacitor)
  • Enter the correct sha-1 in the android client. (google cloud platform)

@sawaca96 Using web client ID instead of android solved the issue for me, thanks! Maybe this is because the capacitor app in the end is a simple webview and therefore should be using the web client id? Anyway, the point is that it’s working now, thanks for the suggestion!

@espositofulvio

Regardless of the environment, such as debug, staging, and production, you have to use sha-1 of the keystore that you used to build the app

and then fill the sha-1 for the OAuth client of the Google cloud platform.

Ok found the answer by myself. You need the fingerprint from the debug.keystore which is in the user home folder:

That’s right. If you haven’t set up anything, that keystore will be used.

What difference between serverClientId and androidClientId ?