CapacitorGoogleAuth icon indicating copy to clipboard operation
CapacitorGoogleAuth copied to clipboard

Android ClientId do not working, but Web ClientId do working

Open sawaca96 opened this issue 2 years ago • 20 comments

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 ?

sawaca96 avatar Oct 29 '21 06:10 sawaca96

What difference between serverClientId and androidClientId ?

sawaca96 avatar Nov 01 '21 04:11 sawaca96

What difference between serverClientId and androidClientId ?

me to

UTSOURCE avatar Nov 05 '21 03:11 UTSOURCE

Hello, can someone from @CodetrixStudio reply to this thread? 🙏

LeCoupa avatar Nov 16 '21 19:11 LeCoupa

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 avatar Dec 13 '21 01:12 sawaca96

thanks yall. super helpful.

I found that my emulator was super buggy, but I was able to test successfully on an actual android device.

bfine9618 avatar Jan 31 '22 18:01 bfine9618

@sawaca96 does that means that I have to sign also the debug version of the apk to use it correctly? I'm not using Android Studio and it's a bit difficult to get the signing thing working for debug build in capacitor compared to cordova which happily accept a build.json file where I can simply put the config for signing.

espositofulvio avatar Feb 22 '22 09:02 espositofulvio

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

keytool -list -v -keystore "C:\Users\USERNAME\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

replace USERNAME with your windows username to get the SHA-1 fingerprint and use that.

espositofulvio avatar Feb 22 '22 10:02 espositofulvio

@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.

sawaca96 avatar Feb 22 '22 11:02 sawaca96

Hi, I have the exact same problem but on capacitor-google-auth version 2.1.3 @sawaca96 has this happened to you with earlier versions as well ?

RAPHAELSTZ avatar Mar 16 '22 12:03 RAPHAELSTZ

@RAPHAELSTZ

I don't know what happened in earlier version.

I use 3.1.0

sawaca96 avatar Mar 17 '22 00:03 sawaca96

@sawaca96

Did you experience problem when doing sigin in android? It keeps saying something went wrong when doing signin in android [getting the results of the sign in]

kevinpallado avatar Apr 04 '22 08:04 kevinpallado

Hi @kevinpallado,

The problem on my end was that on android you need to use the same key hash config on firebase end as the one you use to sign the app on Android Studio. (also, you need to export the correct google-service.json in the appropriate folder)

Using the same one solved my issue.

RAPHAELSTZ avatar Apr 04 '22 08:04 RAPHAELSTZ

@kevinpallado

Yes, I've experiences. I made two OAuth clients and solved something went wrong. One is a web application client and the other is an Android client.

Use Id of the web application client to configure capacitor image

And go to google Android client configure, there is a input place for SHA-1. Put the SHA-1 value of the Android app that is you are using image

sawaca96 avatar Apr 05 '22 00:04 sawaca96

@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!

Lzolcsi avatar May 12 '22 07:05 Lzolcsi

Does not using the web client id expose the app to anyone who can get hold of the client ID? The mobile app origin is always localhost, client id can easily be found in the apk...

mirko77 avatar Aug 01 '22 15:08 mirko77

Wondering the same thing. However, we already established that the SHA1 in Android ID must match the signing key of the app package, so my guess is you quota should still be safe. This is only a guess though and I'd love feedback from someone who knows.

crowbait avatar Sep 18 '22 16:09 crowbait

This plugin sure is strange. Been trying to fetch the email

const logIn = async () => {
     try {
       const response = await GoogleAuth.signIn();
		alert(JSON.stringify(response.getBasicProfile().getEmail()));
		
		
     } catch (e) {
       //
     }
   };

or any other way and so far i can click but i cant obtain the email address.

britisharmy avatar Jan 15 '23 17:01 britisharmy

androidClientId for others help SHA1 for debug keystore can be generated from this link to test keytool -list -v -keystore "C:\Users\USERNAME.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

technophilix avatar Apr 11 '23 13:04 technophilix

In my case, server.androidScheme in capacitor.config.ts was the cause for blank screen of android (without any log in logcat). If I set some value, I get blank screen. At least, I could mitigate the issue by not setting the value. I found out this behavior by comparing my project with bare-bones scaffold project.

pad01g avatar May 08 '23 03:05 pad01g

Dont waste your valuable time on this error. Its same error on react native cli and expo. Even on Auth0, there are still errors if you follow the rabbit hole long enough.

britisharmy avatar May 08 '23 20:05 britisharmy