ios Google Sign in Flutter网页整合

uttx8gqw  于 12个月前  发布在  iOS
关注(0)|答案(1)|浏览(129)

我在flutter web framework中集成google sign in web包时遇到了问题。我想找回idToken,但我做不到。

final GoogleSignIn _googleSignIn = GoogleSignIn(
    clientId:  'my client id'
    signInOption: SignInOption.standard,
    scopes: [
      'email',
    ],
  );
     _googleSignIn.onCurrentUserChanged
            .listen((GoogleSignInAccount? account) async {
    
          // In mobile, being authenticated means being authorized...
          bool isAuthorized = account != null;
          debugPrint('silentUserLogin account is : $account');
          // However, in the web...
          if (kIsWeb && account != null) {
            isAuthorized = await _googleSignIn.canAccessScopes(scopes);
          }
    
    
          // Now that we know that the user can access the required scopes, the app
          // can call the REST API.
        });

在widget中,我这样做了

/// Renders a web-only SIGN IN button.
Widget buildSignInButton({HandleSignInFn? onPressed}) {
  return (GoogleSignInPlatform.instance as web.GoogleSignInPlugin)
      .renderButton();
}

我收到了这个

GoogleSignInAccount:{displayName: Brahim CHEBBI, email: [email protected], id: 113873915042996649214, photoUrl: https://lh3.googleusercontent.com/a/AAcHTtdesTEaIgpxbI0e3jxNnPwkwEe6K_ylHIAea7uDdBfnIg=s96-c, serverAuthCode: null}

我不明白为什么serverAuthCode为null,我想知道如何检索idToken。

iqih9akk

iqih9akk1#

我正在尝试这种方法,但后来我确实使用Firebase包和工程,试试这个。为一个简单的按钮更改UI并调用该函数。
1.使用Firebase方法:这将确保提示用户从其Google帐户列表中选择帐户。为此,请将以下代码添加到signInWithPopup()方法中:

if (kIsWeb) {
  final GoogleAuthProvider provider = GoogleAuthProvider()
      .setCustomParameters({'prompt': 'select_account'});
  await _firebaseAuth.signInWithPopup(provider);
}

相关问题