flutter: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audience is not a valid client ID., null)

flutter: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audience is not a valid client ID., null)

我正在尝试将 google 登录(没有 firebase)添加到我的 flutter 应用程序中。

我已经创建了 google 云项目,创建了 oauth 同意屏幕和凭据。我正在使用

  google_sign_in: ^5.3.2
  googleapis: ^9.0.0

我还必须添加

 <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>com.googleusercontent.apps.618518636914-abc</string>
    </array>
</dict>

允许 ios 启动浏览器以 google 登录,我可以输入电子邮件和密码,之后是应用程序权限屏幕(此应用程序想要访问您的 google drive... ) 屏幕短暂出现又消失,我可以在终端中看到这个错误

   [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audience is not a valid client ID., null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
<asynchronous suspension>
#2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:377:43)
<asynchronous suspension>
#3      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:247:30)
<asynchronous suspension>
#4      GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:377:5)
<asynchronous suspension>

这是用于登录的代码

class GoogleSignInApi {
  static final _googleSignIn = GoogleSignIn(
      hostedDomain: "",
      clientId:
          "618518636914-abd.apps.googleusercontent.com");

  static Future<GoogleSignInAccount?> login() => _googleSignIn.signIn();
}

我提到了这个 post Google Api and android Oauth INVALID_AUDIENCE error, but my client id is correct and it's of type iOS client only (in google oauth credentials) and 这是纯粹的 iOS 项目,它可能仍然相关。但我无法弄清楚 iOS 的 AppAuth 的版本,它被 flutter 的 google_sign_in.

使用

非常感谢任何帮助,谢谢。

请检查以下步骤

  1. 打开xcode和select运行器,然后右键单击运行器并select将文件添加到运行器。在弹出窗口 window 中确保选中复制文件。浏览并 select Google 服务 plist 文件。

  2. 确保您在 Info.plist

    中添加了来自 GoogleServicesInfo.plist id 的反向客户端 id
  3. 从设备中删除现有应用并重新安装。