react-native-google-signin / google-signin

Google Sign-in for your React Native applications
https://react-native-google-signin.github.io/
MIT License
3.12k stars 877 forks source link

Confused about 'webClientId' and Firebase #1216

Closed Tobjoern closed 6 months ago

Tobjoern commented 7 months ago

We are using expo and the google sign in works fine, but I have some question about the way it works exactly.

We set it up, by adding the 'google-services.json' and 'GoogleService-Info.plist' files. From my understanding these files add the 'Native' Google Oauth Keys to the App, which this library uses.

On Apple it works fine, but for some reason, we need to add the 'webClientId' to the configure call, for it to work on Android.

My question is what the 'webClientId' does exactly? Does it only work on Android or also on iOS? If it works on both, what is the purpose of the 'iosClientId'?

Can we use the 'webClientId' instead of the 'google-services.json'?

Kind regards

vonovak commented 6 months ago

Hello and thanks for asking,

We set it up, by adding the 'google-services.json' and 'GoogleService-Info.plist' files. From my understanding these files add the 'Native' Google Oauth Keys to the App, which this library uses.

they contain the client IDs (web, ios, android) and some more firebase-related stuff. Using these files is not mandatory, because you can provide the IDs as parameters to the module, for example:

    const userInfo = await GoogleOneTapSignIn.signIn({
      webClientId: config.webClientId,
      iosClientId: config.iosClientId,
    });

On Apple it works fine, but for some reason, we need to add the 'webClientId' to the configure call, for it to work on Android.

it'd help to know what exactly the problem is :).

My question is what the 'webClientId' does exactly? Does it only work on Android or also on iOS? If it works on both, what is the purpose of the 'iosClientId'?

The web client ID is usually needed for the ID token, if you want to send it over to your server, for example to create a user account. You will find the web client ID in the "aud" (audience field - identifies the recipients that the JWT is intended for) in the decoded ID token. It works both on Android and on iOS.

The purpose of iosClientId is to identify your app with Google (in conjunction with bundle identifier). On Android, this is done differently - using the SHA-1 hash of app's signing certificate in conjunction with the package name.

Can we use the 'webClientId' instead of the 'google-services.json'?

google-services.json file is optional so in the scope of google sign in, yes. But you'll have to provide iOS client ID and maybe some other config options too.

Hope this answers the questions, feel free to ask more :)

Thank you 🙂