简体   繁体   中英

Google sign in for flutter web - Request offline access

I am using google_sign_in_web 0.10.2 https://pub.dev/packages/google_sign_in_web and following the posted example

Here is some of the relevant code:

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


  @override
  void initState() {
    super.initState();
            _googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount? account) {
          setState(() {
            _currentUser = account;
          });
          if (_currentUser != null) {
            _handleGetContact(_currentUser!);
          }
        });
        _googleSignIn.signInSilently();
      }

I can't find a way to set the access_type to offline .

Is this set by default by the library? Else how?

Thank you.

It looks like this is currently not possible: the source code of this library explicitly mentions it:

    // On Android, there isn't an API for refreshing the idToken, so re-use
    // the one we obtained on login.
    response.idToken ??= _idToken;

https://github.com/flutter/plugins/blob/main/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart#L102

There are also open issues and an open pull request which address this issue:

But it is coming!

It looks like very recently (5 days ago) a new parameter forceCodeForRefreshToken has been merged into the development version: https://github.com/flutter/plugins/pull/6130 and will be coming into 6.1.0 (not released yet).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM