簡體   English   中英

Google 登錄 flutter web - 交換刷新和訪問令牌的授權碼

[英]Google sign in for flutter web - exchange authorization code for refresh and access tokens

我正在使用 google_sign_in_web 0.10.2 https://pub.dev/packages/google_sign_in_web並遵循發布的示例

以下是一些相關代碼:

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();
      }

我找不到將授權代碼交換為刷新和訪問令牌的方法

編輯:好的,我找到了訪問令牌:

一旦你有了上面的_currentUser ,你就可以了

final authentication = await _currentUser.authentication;

print(authentication.accessToken);

我仍然需要刷新令牌

好的,我找到了訪問令牌:

一旦你有了上面的_currentUser ,你就可以了

final authentication = await _currentUser.authentication;

print(authentication.accessToken);

GoogleSignIn 在 accessToken 旁邊提供 idToken。

final GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;

googleSignInAuthentication.accessToken
googleSignInAuthentication.idToken

請參考這個答案https://stackoverflow.com/a/62230577/14729495

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM