-->

Did anyone manage to get the id token from google

2020-08-14 07:23发布

问题:

I am trying to connect my users with my back end server , i used the example from the official google sign in plugin for flutter : https://pub.dartlang.org/packages/google_sign_in

the sign process goes fine and i get the username and email ect.. but i need the id Token to authenticate the user with my server.

Ps: Not using firebase , only google sign in.

Can anyone guide me how to get the id Token ?

回答1:

You can try using this

 _googleSignIn.signIn().then((result){
          result.authentication.then((googleKey){
              print(googleKey.accessToken);
              print(googleKey.idToken);
              print(_googleSignIn.currentUser.displayName);
          }).catchError((err){
            print('inner error');
          });
      }).catchError((err){
          print('error occured');
      });


回答2:

or try like this if id token was null, it worked for me.

As the docs point out you need oauth2 client id of your backend to request idToken or serverAuthCode.

from firebase google sigin in authentication copy the Web SDK configuration add paste in the following to res/values/strings.xml, That should work

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="default_web_client_id">{Web app Client id goes here}</string>
</resources>