flutter google_sign_in get id token without firebase

949

Yes You can.

I had this working long time back with PHP that would take care of the google-auth token validation.

This is with respect to google_sign_in: ^4.4.2

The Github Sample Project

  1. Create a GCP project at https://console.cloud.google.com/projectcreate

  2. Next go to https://developers.google.com/identity/sign-in/web/sign-in and select Configure Project, client as Android. Enter Package name and SHA1

Generating SHA1 signing certificates.

  1. Execute in terminal (assign a password and some other parameters)

    keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias androiddebugkey

  2. From the above step you will have a key.jks file for you.

  3. In android/app/build.gradle under android add these settings:

    signingConfigs {
        debug {
            storeFile file('key.jks') 
            storePassword 'epynic'
            keyAlias 'androiddebugkey'
            keyPassword 'epynic'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
    }
    

    storeFile file('/home/epynic/key.jks') - path to your key file generated in step 2

    storePassword 'epynic' & keyPassword 'epynic' the password used to generate the key in step 2.

  4. In termial execute keytool -keystore key.jks -list -v and in the output you’ll have the SHA-1 fingerprint.

  5. Find your package name at AndroidManifest.xml file, under the package= attribute.

Share:
949
Sano
Author by

Sano

Updated on December 31, 2022

Comments

  • Sano
    Sano over 1 year

    I looked at a lot of post related to this topic but none were able to solve my problem so here it is: I use google_sign_in to be able to authenticate with a gmail account all without going through firebase. Everything is going well and I retrieve the user information well but the concern is that the value of my idToken is null whatever my manipulation. However, I did register my app via the google console and here is my code:

    final GoogleSignInAccount user = await googleSignIn.signIn();
      GoogleSignInAuthentication googleSignInAuthentication = await user.authentication;
      print('======== Google auth ===========');
      print(googleSignInAuthentication.accessToken);
      print(googleSignInAuthentication.idToken);
      print('===================');
    

    And here is what it returns to me: enter image description here

    I get the access token well but the token id is null and I would like to know:

    • Is it possible to retrieve the idToken without going through firebase when you have a custom API?
    • If not, in which part is the method entered to be able to retrieve this token?
  • Sano
    Sano over 2 years
    Sorry for the response time, I have already performed these steps but unfortunately it still results in a null idtoken.
  • dustinnoyes
    dustinnoyes over 2 years
    Still getting null for idtoken as well.