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

macOS集成Google SignIn遇client_secret缺失错误的技术问询

macOS Google SignIn 解决 "client_secret is missing" 错误

问题原因

你当前使用的是Web应用类型的Client ID,而macOS原生应用属于桌面客户端范畴,这类客户端不需要client_secret,使用Web类型的Client ID会触发该错误。

解决步骤

1. 替换为桌面应用的Client ID

  • 打开Google Cloud控制台,找到你创建的**桌面应用(Desktop app)**类型的Client ID。
  • 更新Info.plist中的GIDClientID值为桌面应用的Client ID:
<key>GIDClientID</key>
<string>你的桌面应用ClientID.apps.googleusercontent.com</string>
  • 确保CFBundleURLSchemes中的值对应桌面应用Client ID的前缀:
<key>CFBundleURLSchemes</key>
<array>
    <string>com.googleusercontent.apps.你的桌面应用ClientID前缀</string>
</array>

2. 调整GIDServerClientID(可选)

如果你的应用需要向自己的后端发送验证请求,GIDServerClientID应使用Web应用类型的Client ID(后端验证需要这个),但前端登录必须用桌面应用的Client ID。如果暂时不需要后端验证,可以移除这个配置项。

3. 清理缓存并重启

  • 清理Xcode的Derived Data(Xcode > Settings > Locations > Derived Data,点击删除)。
  • 重启Xcode和你的macOS应用,确保配置生效。

验证代码

你的登录代码无需修改,只要Client ID配置正确,就能正常触发登录流程:

@objc func button1Clicked() {
    if let window = view.window {
        GIDSignIn.sharedInstance.signIn(withPresenting: window) { signInResult, error in
            debugPrint("Error \(error)")
            guard error == nil else { return }
            guard let signInResult = signInResult else { return }
            let user = signInResult.user
            let emailAddress = user.profile?.email
            let fullName = user.profile?.name
            let givenName = user.profile?.givenName
            let familyName = user.profile?.familyName
            let profilePicUrl = user.profile?.imageURL(withDimension: 320)
            
            // 登录成功后的逻辑处理
        }
    }
}

错误说明

Error Optional(Error Domain=org.openid.appauth.oauth_token Code=-2 "invalid_request: client_secret is missing." ...)

该错误明确指出请求缺少client_secret,这是因为Web应用类型的Client ID要求必须携带该参数,但桌面客户端设计为无需此参数,因此必须使用对应类型的Client ID。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 21:25:17