0

Is there a way to get the access token and refresh token from google sign in with flutter? I'm using: google_sign_in: ^3.0.4

Joseph Arriaza
  • 12,014
  • 21
  • 44
  • 63

2 Answers2

0

You can create your own implementation of the google_sign_in class. In the end it's just an OAuth token. Here's a web implementation of a custom google_sign_in service: https://stackoverflow.com/a/69746036/5492496

I'm pretty sure you can do the same for Android & iOS using web view.

RMK
  • 1,897
  • 1
  • 10
  • 17
-3

You can try getting it this way:

 GoogleSignIn _googleSignIn = new GoogleSignIn(
    scopes: <String>[ 
      'profile',
      'email',
      'https://www.googleapis.com/auth/contacts.readonly',
    ],
  );

      _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');
      });
nonybrighto
  • 8,752
  • 5
  • 41
  • 55
  • 4
    Does that give you the refresh token though? I'm trying to avoid having to do a Google sign in every time the app opens, which I think was the original spirit of this question as well. – ItsJason Jan 31 '19 at 01:25
  • Did you find any result? – Tim Dirks Nov 13 '19 at 10:24
  • 4
    This shouldn't be an accepted answer as the refreshToken isn't a returned result value from this authentication call. The accessToken will expire quickly (relatively) and the user will need to be prompted again to login (or errors). It appears that the refreshToken isn't currently being made available in the google_sign_in package. There's a Github issue tracking it: https://github.com/FirebaseExtended/flutterfire/issues/1079 – Josh Metcalfe Dec 04 '19 at 03:08