首页 > 解决方案 > “client_secret 丢失。” 在 iOS 中 Google 登录

问题描述

我正在尝试将 Google OAuth2 集成到我的 Swift 应用程序中。
按照指南,我可以安装库并添加按钮。谷歌登录提示打开,但是当我登录时请求失败并显示 400:

Error data:
{
    error = "invalid_request";
    "error_description" = "client_secret is missing.";
}

这是我的视图代表:

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // …

    // Initialize sign-in
    GIDSignIn.sharedInstance().clientID = "(xxx).apps.googleusercontent.com"
    GIDSignIn.sharedInstance().delegate = self

    return true
}

我不知道如何设置秘密,文档中没有提到它?

标签: iosoauthgoogle-apigoogle-signin

解决方案


我的修复:

  1. 转到GTMOAuth2项目中的 pod(在 下Pods

  2. 打开GTMOAuth2Authentication.m

  3. 转到功能authenticationWithServiceProvider

  4. 更改clientSecret为您的秘密。

  5. 构建项目

在此处输入图像描述

当我运行时pod install,GIDSignIn 碰到了几个版本,导致我的代码恢复到原来的状态。希望这可以帮助!


推荐阅读