You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter google_sign_in插件Android端serverAuthCode始终返回null问题

Flutter google_sign_in插件无法获取serverAuthCode问题

认证流程

  • 用户通过Google OAuth2登录
  • 获取server_auth_code并发送至后端完成认证
  • 后端验证授权码后向用户返回JWT

问题描述

该流程在原生Java Android SDK中可正常运行,但使用Flutter的google_sign_in插件时,始终无法获取到serverAuthCode,返回值一直为null。我已尝试使用Android客户端ID测试,也试过Google自动生成的Web应用客户端ID,问题仍未解决。

当前使用代码

/// Provides the `GoogleSignIn` class
import 'package:google_sign_in/google_sign_in.dart';

class GoogleLoginPage extends Stateful Widget {

  final String name = "Logging in with google.";

  late GoogleSignIn _googleSignIn;

  GoogleLoginPage() : super() {
    _googleSignIn = GoogleSignIn(
        scopes: ['https://www.googleapis.com/auth/userinfo.email',
        'https://www.googleapis.com/auth/userinfo.profile'],
        serverClientId: "XX-XXX.apps.googleusercontent.com"
    );
  }

  Future<void> fetchAuthToken() async {
    try {
      var response = await _googleSignIn.signIn();
      log(response?.serverAuthCode ?? "No server auth code");
      _googleSignIn.signOut();
    } catch (error) {
      print("ERR");
      print(error);
    }
  }

  @override
  State<GoogleLoginPage> createState() => GoogleLoginState();

}

代码输出

[log] No server auth code

疑问

我是否存在操作错误?已知Google控制台配置无问题,因Java实现可正常运行。


内容的提问来源于stack exchange,提问作者Dalton Burchard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 00:45:25