CodetrixStudio / CapacitorGoogleAuth

Capacitor plugin for Google Auth. Lightweight & no dependencies.
MIT License
284 stars 158 forks source link

Android ClientId do not working, but Web ClientId do working #157

Open sawaca96 opened 3 years ago

sawaca96 commented 3 years ago

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 commented 3 years ago

What difference between serverClientId and androidClientId ?

UTSOURCE commented 3 years ago

What difference between serverClientId and androidClientId ?

me to

LeCoupa commented 2 years ago

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

sawaca96 commented 2 years ago

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

bfine9618 commented 2 years ago

thanks yall. super helpful.

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

espositofulvio commented 2 years ago

@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 commented 2 years ago

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.

sawaca96 commented 2 years ago

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

RAPHAELSTZ commented 2 years ago

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 ?

sawaca96 commented 2 years ago

@RAPHAELSTZ

I don't know what happened in earlier version.

I use 3.1.0

kevinpallado commented 2 years ago

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

RAPHAELSTZ commented 2 years ago

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.

sawaca96 commented 2 years ago

@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

Lzolcsi commented 2 years ago

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

mirko77 commented 2 years ago

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

crowbait commented 2 years ago

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.

britisharmy commented 1 year ago

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.

technophilix commented 1 year ago

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

pad01g commented 1 year ago

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.

britisharmy commented 1 year ago

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.

ashraful61 commented 2 months ago

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)

Working with the app-release.apk file only, but not the app-release.aab file after uploading playstore. why? could you help?